Skip to content

Instantly share code, notes, and snippets.

@mbaykara
Created September 7, 2021 07:53
Show Gist options
  • Save mbaykara/ac8c37cc8d304025895165ef71e51a8b to your computer and use it in GitHub Desktop.
Save mbaykara/ac8c37cc8d304025895165ef71e51a8b to your computer and use it in GitHub Desktop.
Clean Azure Container Registry
# !/bin/env bash
echo "This script deletes data!"
REGISTRY=production
size=$(az acr repository list -n $REGISTRY -u $USER -p $PASSWORD | jq length --)
for i in `seq 1 $size`;
do
tmp=$(az acr repository list -n $REGISTRY -u $USER -p $PASSWORD | jq .[$i])
REPOSITORY=$(echo $tmp | sed 's/"//g')
echo "Cleaning repository: $REPOSITORY"
##if you are sure with deleted task then remove --dry-run arg
PURGE="acr purge --filter "$REPOSITORY:^.*dev.*$" --filter "$REPOSITORY:^.*remove.*$" --filter "$REPOSITORY:^.*umxmig.*$" --untagged --ago --dry-run 30d"
az acr run --cmd "$PURGE" --timeout 3600 --registry $REGISTRY /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment