Azure DevOps pipelines. Can a custom task somehow detect that the user has cancelled the build/release job mid-execution and quit gracefully? I'm wondering about both the Node API and the Powershell API.
To clarify, I'm talking about this kind of cancel:
Not about conditional execution of tasks.
Nothing to that effect at https://github.com/microsoft/azure-pipelines-task-lib/blob/master/node/docs/azure-pipelines-task-lib.md
"Impossible" is an acceptable answer.
In DevOps pipeline,
Cancel
is not detected inside the task, but in thecondition
expression.For example, the last task will run only when it's canceled before.
You can set the
condition
onstage
,job
andstep
level. Please check the official docs below for the details:Pipeline behavior when build is canceled
Job status check functions
With the condition, make sure the task will run even it's canceled by user, then you can consider what to check inside the task.
For example, to get the job, task status in current build(rest api here)
Edit, update based on the new screenshot:
As per the screenshot, you are canceling for classic release pipeline.
The situation could be complicated:
immediately
cancel it, cannot detect the cancel in task.If you check the run log, it shows
no stage deployed
as below:In the powershell task:
With custom condition in the task behind:
Can detect the canceling in rest api response -> deploysteps -> operationstatus.