We have a scenario where once we manually cancel a pipeline in Azure DevOps, we need to terminate a particular process (exe). We wanted to know how can a task be triggered in YAML post cancellation, to achieve this.
-
Hi @AshwinHariharan, How are things going? Is the suggestion in my answer helpful to you? please have a try with it. Any update, feel free to tell us. – Bright Ran-MSFT Mar 24 '21 at 06:44
-
@Bright Ran-MSFT. Your suggestion worked perfectly for our task. Thanks for the inputs on this. – Ashwin Hariharan Mar 30 '21 at 08:46
-
Hi @AshwinHariharan, you're welcome, and glad that I can help you solve the problem. If possible, could you please mark my answer as the solution of this topic? This may be also very helpful to other people who are looking for a solution for the similar problems. Thanks. – Bright Ran-MSFT Mar 30 '21 at 08:51
3 Answers
Please try with the following ways:
If there are multiple jobs in your pipeline, make sure the job that runs the task to
terminate the particular process (exe)
is processed after all other jobs have completed processing (Succeeded
,Failed
orCanceled
). You can use the 'dependsOn' key to set the execution order of the jobs. For more details, see "Dependencies".Then, as
@ShaykiAbramczyk
mentioned, on the job thatterminates the particular process (exe)
, you can use the 'condition
' key to specify the condition under which the job runs. For more details, see "Conditions".jobs: . . . - job: string dependsOn: string condition: eq(variables['Agent.JobStatus'], 'Canceled')
If there is only one job in your pipeline, make sure the task to
terminate the particular process (exe)
is the last step in the job. You need to put this task to the bottom of the steps list of this job.Then also need to specify the condition on the task to
terminate the particular process (exe)
.If using the '
condition
' key on this step, this step will be always listed and display in the job run, regardless of whether it is skipped or not.steps: - step: string condition: eq(variables['Agent.JobStatus'], 'Canceled')
If using the '
if
' statement on the step, this step will be listed and display in the job run only when the 'if
' condition is met and to run this step. If the condition is not met and the step is skipped, this step will be hidden in the job run.steps: - ${{ if eq(variables['Agent.JobStatus'], 'Canceled') }}: - step: string

- 5,190
- 1
- 5
- 12
You can add the step that terminate the process, and configure him to run only if the pipeline is canceled - with custom condition:
condition: eq(variables['Agent.JobStatus'], 'Canceled')

- 36,824
- 16
- 89
- 114
You can add the step that terminate the process, and configure him to run only if the pipeline is canceled - with canceled() condition:
condition: canceled()

- 8,326
- 3
- 31
- 56

- 1
- 2