Reputation: 1199
I want to send the notification if anything in the stage fails. How can I set the condition in the Release pipeline's task so the task is run when anything previously failed?
The marked option works only for the immediate predecessor.
But consider a situation there is a task which failed, then there is a task which will be run always and after that one is the task I want to run if anything fails.
Upvotes: 1
Views: 12060
Reputation: 950
This is an old thread but in case someone is facing the same issue, I managed to achieve the condition "if anything fails" by using the predefined variable [Agent.JobStatus]
. It has the following statuses :
Having the values above I set the following custom condition:
eq(variables['Agent.JobStatus'], 'SucceededWithIssues')
If you wish to have multiple custom conditions, you can use logical operators as follows :
or(eq(variables['Agent.JobStatus'], 'Canceled'),eq(variables['Agent.JobStatus'], 'Failed'),eq(variables['Agent.JobStatus'], 'SucceededWithIssues'))
Result:
Upvotes: 6
Reputation: 4556
As mentioned in the other answer, you need to use a custom condition and set it to failed()
. But that alone won't do the trick. I believe you could achieve what you want by listing all the previous jobs being run before the Notification
job in its dependsOn
field. That way, if any of the listed jobs fails, your Notification
job will be executed.
jobs:
- job: Build
(...)
- job: CleanUp
(...)
- job: Notification
dependsOn:
- Build
- Cleanup
condition: failed()
steps:
- task: (...)
Upvotes: 0
Reputation: 72171
I think you need to use custom condition and set it to failed()
quote:
With no arguments, evaluates to True only if any previous job in the dependency graph failed.
Upvotes: 1