我想删除 Azure 容器注册表中除最后两个之外的所有映像。我正在寻找一个脚本来执行此操作,但我发现只能删除 X 天之前的图像。这对于我的情况来说是不可能的,因为有些日子会创建很多图像,而其他日子则只有一张。
有人有什么想法吗?
将 $skipLastTags 和 $registryName 的值修改为您的选择并在 powershell 上运行此脚本。
注意:请验证您的本地系统上是否安装了 az cli。
$registryName = 'registryName'
$doNotDeleteTags = ''
$skipLastTags = 4
$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
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)