我正在尝试编写清理脚本。该脚本应该删除旧的 ACR 图像。这里是在 Jenkins 中运行的 sh 命令:
ACRS=( mydevacr )
for ACR in "\${ACRS[@]}"
do
readarray -t repos < <(az acr repository list --name \$ACR | jq -cr '.[]')
for imageName in "\${repos[@]}"; do
readarray -t tags < <(az acr repository show-tags -n \$ACR --repository \$imageName --orderby time_desc | jq -cr '.[]')
for tag in "\${tags[@]:30}"
do
az acr repository delete -n \$ACR --image "\$imageName:\$tag" --yes
done
done
done
它按预期运行了一段时间,但随后,如这里所见,发生了一些无法解释的事情。此外,它作为 Jenkins 管道运行,因此我必须转义 $ 以便 Groovy 不会尝试处理它们。
+ for tag in "${tags[@]:30}"
+ az acr repository delete -n mydevacr --image frontend-dev:606 --yes
WARNING: This operation will delete the manifest 'sha256:44355fdb6becffc44d2cc6a4f3d00d9d7963bf00fbe4375e' and all the following images: 'frontend-dev:606'
+ for tag in "${tags[@]:30}"
+ az acr repository delete -n mydevacr --image frontend-dev:605 --yes
WARNING: This operation will delete the manifest 'sha256:8e48ac6c8b51458b4846c10b01260d74cbb11ac3c7f52c5' and all the following images: 'frontend-dev:605'
+ for tag in "${tags[@]:30}"
+ az acr repository delete -n mydevacr --image frontend-dev:604 --yes
WARNING: This operation will delete the manifest 'sha256:2b443ff1da9604b4b4a3b1831095375b6fd72c19c39e2e93'
and all the following images: 'frontend-dev:525', 'frontend-dev:526', 'frontend-dev:527',
'frontend-dev:528', 'frontend-dev:529', 'frontend-dev:530', 'frontend-dev:531', 'frontend-dev:533',
'frontend-dev:534', 'frontend-dev:535', 'frontend-dev:536', 'frontend-dev:537', 'frontend-dev:538',
'frontend-dev:539', 'frontend-dev:540', 'frontend-dev:542', 'frontend-dev:545', 'frontend-dev:547',
'frontend-dev:549', 'frontend-dev:550', 'frontend-dev:551', 'frontend-dev:555', 'frontend-dev:556',
'frontend-dev:557', 'frontend-dev:558', 'frontend-dev:559', 'frontend-dev:560', 'frontend-dev:561',
'frontend-dev:562', 'frontend-dev:563', 'frontend-dev:565', 'frontend-dev:566', 'frontend-dev:569',
'frontend-dev:571', 'frontend-dev:572', 'frontend-dev:574', 'frontend-dev:575', 'frontend-dev:576',
'frontend-dev:577', 'frontend-dev:579', 'frontend-dev:580', 'frontend-dev:581', 'frontend-dev:582',
'frontend-dev:583', 'frontend-dev:584', 'frontend-dev:585', 'frontend-dev:586', 'frontend-dev:590',
'frontend-dev:591', 'frontend-dev:592', 'frontend-dev:593', 'frontend-dev:594', 'frontend-dev:595',
'frontend-dev:596', 'frontend-dev:597', 'frontend-dev:599', 'frontend-dev:600', 'frontend-dev:602',
'frontend-dev:604'
az acr repository delete -n mydevacr --image frontend-dev:604 --yes
仅指定 1 个时,最后一个 az 命令删除 59 个图像。
这怎么可能?
我在这里“匿名”了一些东西,以免透露太多我们的设置。
而且,由于它在 Jenkins Pipeline 中运行,我不得不转义 $ 符号,以便 Groovy 不会尝试处理它们。