Skip to content

Instantly share code, notes, and snippets.

@weinong
Created August 4, 2022 03:48
Show Gist options
  • Save weinong/19141bf3131893c9daac8a24190326bb to your computer and use it in GitHub Desktop.
Save weinong/19141bf3131893c9daac8a24190326bb to your computer and use it in GitHub Desktop.
[Azure DevOps] remove all build retentions from a group of build definitions
#!/bin/bash
INF='\n'
USER=
TOKEN=
ORG=
PROJECT=
for definitionID in (91395 100391 91349 87035 95571 64773 79297 64580 63192 64774); do
for buildID in $(az pipelines build list --org https://dev.azure.com/${ORG}/ -p ${PROJECT} --definition-ids ${definitionID} -o json | jq -r ".[].id"); do
resp=$(curl -s -u "${USER}:${TOKEN}" "https://dev.azure.com/${ORG}/${PROJECT}/_apis/build/builds/${buildID}/leases?api-version=7.1-preview.1")
count=$(echo $resp | jq -r ".count")
if [[ ${count} -ne "0" ]]; then
for leaseID in $(echo $resp | jq -r ".value[].leaseId"); do
echo delete leaseID ${leaseID}
curl -s -X DELETE -u "${USER}:${TOKEN}" "https://dev.azure.com/${ORG}/${PROJECT}/_apis/build/retention/leases?ids=${leaseID}&api-version=7.1-preview.2"
done
fi
done
done
@cn3m0
Copy link

cn3m0 commented Dec 13, 2023

Thanks, it works. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment