Reputation: 97
I need my pipeline to run a task if the build is cancelled either by a user or automatically (by the system itself).
Is there any condition to do so?
Thanks!
Upvotes: 4
Views: 3122
Reputation: 2039
If you need the task to run only when the build is canceled, you need to check both always()
and succeededOrFailed()
.
Because succeededOrFailed()
is false
when the pipeline is canceled, the following condition works:
- script: |
echo "Pipeline was canceled."
condition: and(always(), eq(succeededOrFailed(), false))
Upvotes: 1
Reputation: 394
Yes, you can use always()
steps:
- script: echo I did a thing
condition: and(always(), eq(someConditionHere))
More on that here: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml
Upvotes: 3