ACR Purge - Retain the 10 latest images in my registry

117 views Asked by At

I want to retain the 10 latest (order by date) images and delete the rest, how do i achieve that using command line? I dig through the documentation from azure but didn't find anything related to limit option.

i want to achieve something like the --limit 10 thingy

az acr task create \
  --name "purge-old-images" \
  --resource-group "<RESOURCE_GROUP_NAME>" \
  --registry "<ACR_NAME>" \
  --cmd "az acr purge --name <ACR_NAME> --repository <REPOSITORY_NAME> --untagged --limit 10" \
  --schedule "0 0 * * *"
1

There are 1 answers

0
amit_g On BEST ANSWER

It would be something like this (remove --dry-run after it is tested)

az acr task create \
  --name "purge-old-images" \
  --resource-group "<RESOURCE_GROUP_NAME>" \
  --registry "<ACR_NAME>" \
  --cmd "acr purge --filter '<ACR_NAME>:.*' --untagged --keep 10 --dry-run" \
  --schedule "0 0 * * *"