Remove images (manifests) from an Azure Container Registry (ACR) repository by tag name or date using az acr commands.

Context = MacOS
az login
az -v => azure-cli 2.34.1

Delete a manifest by tag name

Warning: this deletes the manifest, not just the tag. If there are two different tag names that share the same manifest, deleting one tag will delete the other tag.

az acr repository show-tags --name <registry> --repository <repository> | grep \"tagnamestartswithstring' | sed 's/,*$//g' | xargs -I X az acr repository delete --name <registry> --image <repository>:X --yes
Create a list of delete commands by Name

Does not actually delete the image:tag, but creates a list of commands that can be used for deleting individual manifests by image:tag name.

az acr manifest metadata <registry>.azurecr.io/<repository> --query '[].tags[0]' -o yaml | grep 'tagnamestartswithstring' | sed 's/- /az acr repository delete --name <registry> --yes --image <repository>:/g'
Create a list of delete commands by Date

Does not actually delete the image:tag, but creates a list of commands that can be used for deleting individual manifests by image:tag date.

az acr manifest metadata list <registry>.azurecr.io/<repository> --query '[].tags[0]' -o yaml | grep '[1-3]2022-' | sed 's/- //az acr repository delete --name <registry> --yes --image <repository>:/g'

Explanations


Get all the tags for the repository (there are two ways to do this).
az acr repository show-tags --name <registry> --repository <repository>
OR
az acr manifest metadata list <registry>.azurecr.io/<repository> --query '[].tags[0]' -o yaml

Get all the tags that start with the specific input and pipe that to sed which will remove the beginning dash.
grep 'tagnamestartswithstring' | sed 's/- //g'

Assign the output to the variable X, use X as the tag in a delete command, and do not prompt for confirmation (--yes).
xargs -I X az acr repository delete --name <registry> --image image:X --yes