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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With