Azure / azure-devops-cli-extension

Azure DevOps Extension for Azure CLI
https://docs.microsoft.com/en-us/cli/azure/ext/azure-devops/?view=azure-cli-latest
MIT License
618 stars 240 forks source link

Would like to delete individual pipeline runs by id [Feature Request] #1245

Open odelljl opened 2 years ago

odelljl commented 2 years ago

Is your feature request related to a problem? Please describe. I cannot delete pipeline runs from the az pipelines command set. A sample use case would be to delete all pipeline runs that are not run against the main or master branch. I often accumulate pipeline runs when testing a new or updated pipeline on a feature branch in my git repository. When I'm done I want to clean them out of the history - they have no value other than to clutter things up. I have to manually clean them one at a time in the user interface.

Would like to be able refine a query against the runs, then iterate through runs that meet certain criteria and delete them.

Describe the solution you'd like

az pipelines runs delete -id xxxx

dennis-behm commented 5 months ago

Looking for a similar function.

For the time being, I am playing with a bash script:

 - job: Cleanup
        steps:
          - checkout: none 
          - bash: |  
              declare -a buildUrls=$(az pipelines runs list --org <org> --project <prj> --branch <branch> --query '[?url].url | sort(@)')

              buildUrls=${buildUrls:1:-1}
              buildUrls=$(echo $buildUrls | tr -d '"')
              IFS=","
              declare -a urls=($buildUrls)

              for element in "${urls[@]}"; do
                  az rest \
                    --method delete \
                    --headers "Authorization=Bearer $AZURE_DEVOPS_EXT_PAT" \
                    --url $element\?api-version\=7.1-preview.1 \
                    --resource 499b84ac-1321-427f-aa17-267ca6975798
              done
            env:
               AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
            displayName: "Delete Build Runs"