Forum Discussion
How to delete pipeline tags with special characters?
I want to delete specific tags attached to Azure pipeline builds, for example "hello: world". I've come to the conclusion that the ADO REST API endpoint for handling Tag deletions cannot parse special characters in the URL's slug i.e. colons and whitespaces.
According to thehttps://learn.microsoft.com/en-us/rest/api/azure/devops/build/tags/delete-build-tag?view=azure-devops-rest-7.1, the tag should be specified in the URL slug, followed by query string parameters if applicable. I tried the following:
1. If I insert the tag directly into the URL it will look like this:
https://dev.azure.com/organisation/project/_apis/build/builds/1234567/tags/hello: world?api-version=7.1
This returns: "Response status code does not indicate success: 400 (Bad Request)."
2. But if I encode my slug using `[System.Web.HttpUtility]::UrlEncode($tag)`, the URL looks like this:
https://dev.azure.com/organisation/project/_apis/build/builds/1234567/tags/hello%3a+world?api-version=7.1
This returns "Response status code does not indicate success: 404 (Not Found)."
So it seems the encoding might have worked, although it appears to be searching for a tag without decoding the URL first?
Does anyone know if there is a way for deleting tags with special characters? I have over 1600+ tags that need to be deleted so manually doing this through the UI would not be a viable option.
EDIT: I just realised the documentation has a small note saying:
This API will not work for tags with special characters. To remove tags with special characters, use the PATCH method instead (in 6.0+)
Tried the PATCH method instead of DELETE and still not working. And there's no examples provided in the docs.
2 Replies
May consider Power Shell Invoke-RestMethod:
$url = "https://dev.azure.com/organisation/project/_apis/build/builds/1234567/tags?api-version=6.0" $headers = @{ "Authorization" = "Bearer YOUR_PERSONAL_ACCESS_TOKEN" "Content-Type" = "application/json" } $body = @{ "tags" = @("tag1", "tag2") # Include only the tags you want to keep } | ConvertTo-Json -Depth 10 Invoke-RestMethod -Uri $url -Method Patch -Headers $headers -Body $body
- itsmguy20Copper Contributor
This question has been resolved. I have included the solution on Stack-Overflow as this question took longer than expected to go through the review approval process.
Cross-posting solution here:
https://stackoverflow.com/questions/79588243/how-to-delete-pipeline-tags-with-special-characters