79522264

Date: 2025-03-20 08:17:10
Score: 0.5
Natty:
Report link

for linux/bash user: remove all release retentions from a pipeline

#!/bin/bash
PIPELINE_ID=${1}
PROJECT=<PROJECTNAME>
ORGANIZATION=<ORGANIZATIONNAME>
TOKEN="test:<TOKEN>"

leases=$(curl -u "${TOKEN}" -X "GET" "https://dev.azure.com/${ORGANIZATION}/${PROJECT}/_apis/build/retention/leases?api-version=6.0-preview.1&definitionId=${PIPELINE_ID}" | jq .value[].leaseId)
echo $leases
for lease in $leases; do
  echo $lease
  curl -u "${TOKEN}" -X "DELETE" "https://dev.azure.com/${ORGANIZATION}/${PROJECT}/_apis/build/retention/leases?ids=${lease}&api-version=6.0-preview.1"
done

The token can you create from the "User Settings" dropdown in the right top corner.
You can obtain the pipeline ids from the portal, something like this in the URL "_build?definitionId=42"

or use following command to get all names and ids from a project:

curl -u "${TOKEN}" -X "GET" "https://dev.azure.com/${ORGANIZATION}/${PROJECT}/_apis/build/definitions?api-version=3.2" | jq '.value[] | .id,.name'
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: 43n12y