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!
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
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With