Created
August 4, 2022 03:48
-
-
Save weinong/19141bf3131893c9daac8a24190326bb to your computer and use it in GitHub Desktop.
[Azure DevOps] remove all build retentions from a group of build definitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, it works. :)