How can I delete Azure DevOps old build pipelines and there leases with Power Shell

Question:

Hello Azure DevOps Specialists

I do have in Azure DevOps some old build pipelines, that I want to delete using Power Shell.
I wrote a little power shell script to get the build definitions first and then get the build id, name, etc. Before I can delete a definition, the retained releases must be deleted.
The program code is prepared, but the API requires an ownerId or userId or Minimal Retention Leases. And that is my challenge!

I read the documentation https://learn.microsoft.com/en-us/rest/api/azure/devops/build/leases?view=azure-devops-rest-6.0 and the code behind (hosted on GitHub https://github.com/microsoft/azure-devops-node-api/blob/470f9ca7bdfccd87e1c1fdea8023b8c3d2b1047a/api/interfaces/BuildInterfaces.ts#L2006), but I have no idea what the ownerId or userId is or how I can find it.

Can you help me?
Thank you in advance
Tino

Answer:

Stuff in Azure DevOps Portal changes frequently. In February 2022 I composed my own script out of several Stackoverflow posts to remove old Build Pipelines, their Builds and their Leases.

Source:

How can I delete Azure DevOps old build pipelines and there leases with Power Shell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply