Home > Blockchain >  PowerShell script to keep latest 10 images on azure container registry and remaining need to delete
PowerShell script to keep latest 10 images on azure container registry and remaining need to delete

Time:09-22

I need a PowerShell script, always keep latest 10 docker image tags in azure container registry and other images need to delete automatically. This script I need to pass via azure pipeline task like AZ CLI inline script. Can any one help me out this. enter image description here I need to keep latest 10 docker images

Thanks in advance...

CodePudding user response:

I have tried to reproduce the issue by using the docker and pushed the 12 images to Azure container Registry and used the below PowerShell cmdlet to keep the latest 5 images in the ACR and deleted the other images successfully as shown in the below screenshots.

You can use the below azure purge cmdlet to delete the images based on your requirement i.e., 10/15 days ago.

Here i have taken 0(zero) days ago images to be deleted and the latest 5 images to be kept.

az acr run --cmd "acr purge --filter 'hello-world:.*' --ago 0d  --keep 5" --registry testdockeracrcontainer /dev/null

Output after pushing the 12 images to ACR from local: enter image description here

Output after executing the above PowerShell cmdlet: enter image description here enter image description here

  • Related