Stop a Build Pipeline if a Dependent Azure DevOps Pipeline have Failed

In some cases there might be necessary to prevent an Azure (Build) Pipeline from running if some other pipeline in your project fails. Well, I encountered a scenario like this the other day. After spending an hour trying to find an out of the box solution, I concluded that it probably none available yet. However, that’s not an excuse I can live with, so PowerShell and Azure DevOps API to the rescue.

After some scripting, I ended up with the following code that seems to work quite well. Really hope you can use it also, and feel free to comment if you see any improvements that should be added!

All you need to change in this task is

  • {definitionId} on line 34. Replace it with the definition Id from the Build Pipeline you want to check.
  • {organization} and {projectName} on line 35. Replace it with your DevOps organization name and the project name hosting the pipeline.

There might be better ways to solve this, and I would almost expect that there are, but it works, and it solved my challenge for now!

Happy building!

Want to learn more? Check out Building and Publishing .NET Core Micro-Services to Kubernetes

Documentation references

About the Author:

Anders Eide is a Senior Manager at KPMG and are leading the Platform Specialist team in Norway. He is also highly engaged in modern technology communities and has been awarded Microsoft MVP 6 times.


Edide, A (2020). Stop a build pipeline if a dependent Azure DevOps Pipeline have failed. Available at: [Accessed: 19th August 2020].

Share this on...

Rate this Post: