请检查以下使用 azure CLI 命令的脚本是否提供了工作思路:
它使用按标签删除的方法。为此,您需要在系统上安装 azure cli。
$registryName = 'registryName'
$doNotDeleteTags = ''
$skipLastTags = 3
$repoArray = (az acr repository list --name $registryName --output json | ConvertFrom-Json)
foreach ($repo in $repoArray)
{
$tagsArray = (az acr repository show-tags --name $registryName --repository $repo --orderby time_asc --output json | ConvertFrom-Json ) | Select-Object -SkipLast $skipLastTags
foreach($tag in $tagsArray)
{
if ($donotdeletetags -contains $tag)
{
Write-Output ("This tag is not deleted $tag")
}
else
{
az acr repository delete --name $registryName --image $repo":"$tag --yes
}
}
}
参考:Azure Container Registry - 删除除 2 之外的所有图像 - VoidCC
(或者)
az acr repository show-tags -n MyRegistry --repository MyRepository
| ConvertFrom-String
| %{$_.P2 -replace "[",]",""}
| where {$_ -notin "skipthistag","andthistag" }
| % {az acr repository delete --name MyRegistry --image MyRepository:$_ --yes}
参考:如何从 Azure Container Registry 中删除映像 - 代码日志
参考 - 跳过最后 x 个图像:
- 清理 (ACR) | 安德鲁·凯莱赫
- 用于删除旧 ACR 映像的 powershell 脚本 - Microsoft Q&A
其他参考:
- acr-cleanup:(github.com)
- 所以参考
- (ACR):标签、清单和清理 | 通过 Anant Vardhan | 中等的