Reputation: 1975
I'm trying to delete an Azure DevOps build definition but it won't let me since it says:
"One or more builds associated with the requested pipeline(s) are retained by a release. The pipeline(s) and builds will not be deleted."
However there's no obvious way to see what release is causing a build to be retained. I tried searching online, of course, but all the examples/screenshots of how to do this in the web UI are showing UI from several iterations ago of the Azure DevOps website so none of the controls look the same anymore. I don't see a lock icon anywhere, for example.
How can I find the releases that are holding onto these build definitions so I can delete them and then delete the build definition?
Thanks!
Upvotes: 6
Views: 8318
Reputation: 21
To build on the above answers, I used powershell to PATCH each build to set the retainedByRelease flag to false.
First build a file out of the build.id values lets say buildsToPatch.txt. It would just be a line delimited list. Use the $responses
of https://stackoverflow.com/a/58889636/27840602 to construct the list like this:
$defId = <integer> find it in the url of the build pipeline
$results = $response.value | Where {$_.retainedByRelease -eq "true" -and $_.definition.id -eq $defId}
$results > buildsToPatch.txt
Create the patch body:
$body = @{
"retainedByRelease" = "False"
} | ConvertTo-Json
Then call the following powershell:
gc ./buildsToPatch.txt | % {
Invoke-RestMethod -Uri "https://dev.azure.com/your-org/your-project/_apis/build/builds/$($_)?api-version=7.1" -Method Patch -ContentType 'application/json' -Body $body -Headers @{Authorization = "Basic $token"}
}
Note $token
is same as what was used to GET the builds in the answer: https://stackoverflow.com/a/58889636/27840602
This allowed me to then delete the Pipeline for the build I no longer wanted.
Upvotes: 2
Reputation: 33397
I have had this issue when some one delete a repository that was associated with a "POC" pipeline. I was not able to delete the pipeline.
When I tried to delete the pipeline, I got following 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.
I did following steps to delete the pipeline:
Repeat steps 2-4 for each run. When you have delete all builds, now you can delete the pipeline by clicking on the 3 dot menu, as shown in the image below.
Enjoy!
Upvotes: 5
Reputation: 18978
When you open the build pipeline to see its detailed build records, you can see the relevant release name and its link:
On old pipeline version, there had a lock icon which can obvious let us know it is retained. In fact, the lock icon not only means it is retained by release, manual build retain also show this icon. But, seems we missed this obvious icon while we expand the new sprint.
As a workaround to get list of builds which retained by release, here has a short script can help you achieve by using Rest api:
$token = "{PAT token}"
$url ="https://dev.azure.com/{org name}/{project name}/_apis/build/builds?api-version=5.1"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get
$results = $response.value | Where {$_.retainedByRelease -eq "true"} #|
Write-Host "results = $($results.id | ConvertTo-Json -Depth 100)"
First, use list builds api to get all builds that in current project. Then for the builds which retained by release, since there has a parameter can indicate it: retainedByRelease here I use $_.retainedByRelease -eq "true"
to get the builds list which actual retained by release:
The above script is very universal, can be used in Powershell-ise and Powershell Command Line and the Powershell task of VSTS without change anything.
Update in 11/19:
Based on @Auth's comment, if want to get its associated release, the most easiest way is find the build, and then check its associate release pipeline as the screenshot shown I shared above.
If this does not satisfied what you want, and the previous API we used does not include any releases info in that, so here, you need use this API: Releases - Get Release:
GET https://vsrm.dev.azure.com/{org name}/{project name}/_apis/release/releases?sourceId={project id}:{build definition id}&api-version=5.1
In this API, you need specified the project id
:build definition id
to filter releases.
With the icon missing, will let the corresponding team know and try to add it in the future sprint.
Upvotes: 5