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.