nunolima41
nunolima41

Reputation: 97

Execute task when build is cancelled - Azure DevOps Pipelines

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

Answers (2)

colinD
colinD

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

David Petric
David Petric

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

Related Questions