Skip to content

Cannot Delete Azure DevOps Build Pipeline

Photo by Miguel Á. Padriñán: https://www.pexels.com/photo/close-up-shot-of-keyboard-buttons-2882553/

Sometimes even the simplest tasks seems almost impossible to complete. Deleting build pipeline at Azure DevOps can be one of those tasks. In theory you have the Delete button at the triple dot menu that you need to click and that’s it, but in most cases you will encounter an error message “One or more builds associated with the requested pipeline(s) are retained by a release. The pipeline(s) and builds will not be deleted.

Delete button is available at the triple dot menu

Let’s first find out what is causing this issue and then we can see how to fix it. Open up the pipeline that you want to delete and open triple dot menu on first build row. There should be “View retention leases” menu option available. Click it to open the sidebar view of retention leases.

Click triple dot menu on build row and select view retention leases

This open ups the retention rules which are preventing the deletion of this pipeline. As in my example I have three rules: Branch policy, pipeline retention settings and release management. At the bottom there is link to retention policy, which can be used to change these settings in general.

Retention rules that are preventing the pipeline delete

The Deletion

To be able to delete the pipeline we must met all these criteria’s OR we can just remove all retains for this build run, by clicking Remove all at the end of view retention leases sidebar. You may need to go through all the builds that are retained, if you don’t change the retain policies. You can see which builds are retained by looking for little pin symbol next to build run.

Pinned builds are retained

After removing all the retained builds or editing the policies, you should be able to delete the pipeline without any issues. However remember that you may have release pipelines that are using your build as an artifact, so remember to delete those release pipelines also (or update their build pipeline links). If you don’t want to do this whole thing manually, you can also use Azure DevOps Delete Leases API