Reputation: 66
i have create CI/CD pipeline in azureDevops. i need to add custom condition for when only previous task succeeded then it will execute.
so please help me what i have to write in Custom condition ?
I have attached below screen short where i need to add some custom condition.
Upvotes: 1
Views: 332
Reputation: 66
i have found some custom condition which has fulfill my desire task.
in(variables['Agent.JobStatus'], 'Failed', 'Succeeded', 'SucceededWithIssues')
in above custom condition for if the prev task will 'failed' or 'succeeded' next task will executed.
Upvotes: 0
Reputation: 76760
i need to add custom condition for when only previous task succeeded then it will execute.
There is directly option Only when all previous tasks have succeeded
, which is used to determine if all the previous tasks have succeeded.
If you want to give the condition that just when only the one previous task succeeded, there is no such out of box option to use. We could use the workaround that Napoleon answered:
write the result of the previous task to a variable and then check that variable in your condition
In addition, I posted this answer to emphasize the choice of conditions, we need use always()
not succeeded()
or failed()
. That because the syntax of condition is for all previous steps/jobs:
Check the document Conditions for some more details.
For example:
I add three tasks in my pipeline:
Command line-Intentionally let it run failed
Run Inline Powershell-create a variable, assign it a value.
Write-Host "##vso[task.setvariable variable=TaskStatus;]Succeeded"
Command line-Custom Condition checking that variable.
and(always(), eq(variables['TaskStatus'], 'Succeeded'))
If we use the condition succeeded()
or failed()
, whether its execution is still affected by all previous task execution results (First command line task.)
Hope this helps.
Upvotes: 1
Reputation: 565
You could write the result of the previous task to a variable and then check that variable in your condition.
Upvotes: 0