Azure DevOps CICD “Only when all previous tasks have succeeded” doesn’t work workaround

In Azure DevOps Build Pipelines, if you have some build steps like this:

Step1
Step2 (Continue on error)
Step3 (Only when all previous tasks have succeeded)
Step4

What you want is when Step2 failed, continue but do not execute Step3. If Step2 succeeded, continue and execute Step3.

Step2 setting:

Step3 setting:

the actual is: Step3 will execute no matter Step2 failed or not. The reason is in Step2, it turn on “Continue on error”. So even if Step2 failed, it will continue and “all previous tasks have succeeded” will evaluated to true. If you turn off “Continue on error”, when Step2 failed, it will not continue to next step.

How to solve this problem? There is a workaround. We can use Custom condition to evaluate previous steps status, if some of previous steps failed but turn on “Continue on error”, the status will be “SucceededWithIssues”, so we can use the expression:
not(in(variables[‘Agent.JobStatus’], ‘SucceededWithIssues’))

In this way, it will work.

“all previous tasks have succeeded” is so confused and it will give you true if previous steps not stop.

Leave a comment