Is there any way to enable retention policy for Azure ACR repositories, where only last 3 tags is need to keep and rest can be deleted. Also we have to exclude certain images from these repositories ( can be filtered with regex filter, eg: images have prefix "base-image")
Azure container registry repository image custom cleanup
108 Views Asked by Vowneee At
2
There are 2 best solutions below
0
Vowneee
On
From @Jahnavi's solution provided, created a shell script as below to solve our requirement.
#!/bin/bash
reg='xxxx'
skipLastTags=xxx
repositories=$(az acr repository list --name $reg --output json | jq -r '.[]')
for repo in $repositories; do
tags=$(az acr repository show-tags --name $reg --repository $repo --orderby time_asc --output json | jq -r '.[]' | head -n -"$skipLastTags")
for tag in $tags; do
az acr repository delete --name $reg --image "$repo:$tag" --yes
done
done
Related Questions in BASH
- When does Bash read heredocs?
- Why `set -o pipefail` gives different output even though the pipe is not failing
- Run an external command within jq to manipulate each values of a particular key
- API key 401 error in .env.development file
- How to "Enable mobile data" on a Huawei E3372 4G USB dongle using a bash script in Windows
- ImageMagick / Bash : pipe ignored(?) when filename format variable used
- MacOS Bash-Script: while read p and echo
- Parse command line arguments and write useful usage message without additional code
- JQ JSON - Values to Array
- why variable substitution is so different?
- postbank_pdf2csv: how to setup with Cygwin in Windows?
- Custom Bash functions & custom statements - Need some advice
- unexpected operator == in square brackets when trying to use gum lib
- How to disable a bash builtin inside a docker container
- Use sed or rename find series of alphabet then replace with with the same alphabet and a dash -
Related Questions in SHELL
- macOS - Most secure way of a GUI SUDO_ASKPASS
- When does Bash read heredocs?
- Why `set -o pipefail` gives different output even though the pipe is not failing
- Run multiple shell scripts in Dockerfile
- Alias does not take effect when I use Vim to execute external commands
- why variable substitution is so different?
- Error: fish: ${ is not a valid variable in fish
- Custom Bash functions & custom statements - Need some advice
- unexpected operator == in square brackets when trying to use gum lib
- Delete first three lines containing a certain word
- Keep the log for the last 14 days
- Iterate over items in one array and groups of items in second array
- Keep multi-version of a static-lib like what we do for shared-libs
- How to write function in bash for reuse shell commands inside using osascript?
- Why is it that when I pass certain directory names to `ls`, sometimes it does not list their contents?
Related Questions in AZURE-CLI
- Kubernetes : How to connect production and non-production Azure CLI simultaneously through windows system?
- Azure Developer CLI does not recognize environment
- Is there any way to get a new Azure CLI token without logging out?
- Azure Service Principals are not deleting from the Azure CLI
- az functionapp config is truncating trailing bracket
- How to install azure devops extension from powershell script
- Troubleshooting GitHub Secrets: "Invalid Subscription or Tenant Level Error"
- "Directory is expected, not a file." error when using Azure CLI to download from blob storage
- Azure error writing parquet to ADLS Gen 2
- Azure container registry az acr build command times out with 404 BlobNotFound
- Error Exporting disk to a Storage account -Both configured with private endpoints in the same Vnet
- How to create Azure devops service connection via code?
- What Azure account to use to run a python script on multiple azure tenants resources?
- How to add all iterations of a project to all teams in that project?
- Is it possible to show if OAuth is being used for Azure Function App?
Related Questions in AZURE-CONTAINER-REGISTRY
- Azure Container App :ImagePullBackOff on legion when using Private image from Azure Container Registry
- Error while performing acr run build: MONGODB_URI environment variable in .env.local
- Azure container registry az acr build command times out with 404 BlobNotFound
- Access denied for '***', repository does not exist or may require 'docker login': denied: requested access to the resource is denied
- Can I use a different port in Azure Container instances for public access?
- Is there a better way for `az acr import ...` instead of `AzureCLI@2` in Azure DevOps?
- How to share images between ACRs in separate tenants using Azure DevOps agents
- Azure Container App not authorized to access Storage Account Table
- Images pushed via docker(az acr) shows as untagged in the portal
- Azure container instance and a private container registry
- How to fix (TasksOperationsNotAllowed) ACR Tasks requests for the registry <containerRegistryName> and <password> are not permitted
- How to automatically delete container registry images related to an argocd application when application gets deleted?
- Pushing image to Azure Container Registry preconfigured with certain config file
- Azure Container Registry CI/CD with Github Actions not working
- AKS can't pull from ACR registry when using custom vnet + subnet
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You can use delete operation to delete the tags prior.
Acr Delete tag
Check whether the below Azure
CLIscript provides insights to meet your functionality.Refer SO for more relevant information on your requirement.