How to cancel current pipeline job "from within" in Azure ML sdk v2

Celso Araujo 0 Reputation points
2024-11-14T20:06:08.51+00:00

I am porting a sdk v1 machine learning pipeline to SDK v2. It runs on a daily basis on a scheduler. We have a step which, under certain conditions, cancels the whole pipeline job (ie, the other steps won't run). Its code is like this:

from azureml.core import Run
from azureml.pipeline.core import PipelineRun
run = Run.get_context()
ws = run.experiment.workspace
pipeline_run = PipelineRun(run.experiment, run.parent.id)
if condition:
    pipeline_run.cancel()

I can't find a way to do something similar using Python SDK v2. And I don't want to mix v1 and v2 code, since it is a bad practice. How could I do it? Any ideas?

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,976 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.