Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force an Azure DevOps pipeline to fail if any previous tasks have failed?

My YAML-based Azure DevOps pipeline contains several tasks in which continueOnError: true. I did this deliberately so that I can run all test suites even when some of them fail (each task runs a different suite of tests). At the moment the build is marked as 'partially succeeded' if any of these tasks fail. Now how do I force the build to be marked as 'failed' instead?

I could probably do this manually by setting a build variable in each task if it fails, and then checking the value of this variable in a final step. But what's the easiest way to force a build to fail if any of the previous steps in the pipeline have failed?

like image 755
snark Avatar asked Dec 30 '25 10:12

snark


1 Answers

Adding one of these tasks to the end of each job seems to do the trick:

- bash: |
    echo AGENT_JOBSTATUS = $AGENT_JOBSTATUS
    if [[ "$AGENT_JOBSTATUS" == "SucceededWithIssues" ]]; then exit 1; fi
  displayName: Fail build if partially successful

The echo line is optional. See the Azure docs here re the agent variable called Agent.JobStatus and the values it can take.

Or you can use Azure's built-in conditions to check the variable directly:

- bash: exit 1
  displayName: Fail build if partially successful
  condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues')

Making the bash task return any non-zero value will cause it to fail when the condition is met.

like image 99
snark Avatar answered Jan 03 '26 02:01

snark