Skip to content

Instantly share code, notes, and snippets.

@PartTimeLegend
Created March 26, 2021 14:04
Show Gist options
  • Select an option

  • Save PartTimeLegend/74e24d0df5226d80bef930ae2f47a9cc to your computer and use it in GitHub Desktop.

Select an option

Save PartTimeLegend/74e24d0df5226d80bef930ae2f47a9cc to your computer and use it in GitHub Desktop.
Prune ACR
$registry = "myRegistry"
$keep = 5
$prAgo = "7d"
$masterAgo = "90d"
$prCron = "0 0 * * *"
$masterCron = "0 0 * * *"
$repositories = @("foo.bar",
"bar.foo",
"foobar.boofoo",
"barfoo.foobar"
")
foreach ($repository in $repositories)
{
$prefix = $repository.Replace(".","")
$prCmd = "acr purge --filter '${repository}:.*-PullRequest.*' --ago $prago"
Write-Output $prCmd
$prTaskCmd = "az acr task create --name ""${prefix}purgePRTask"" --cmd ""$prCmd"" --schedule ""$prCron"" --registry $registry --context /dev/null"
Write-Output $prTaskCmd
Invoke-Expression $prTaskCmd
#[Console]::ReadKey()
$masterCmd = "acr purge --filter '${repository}:.*' --ago $masterAgo --keep $keep"
Write-Output $masterCmd
$masterTaskCmd = "az acr task create --name ""${prefix}purgeMasterTask"" --cmd ""$masterCmd"" --schedule ""$masterCron"" --registry $registry --context /dev/null"
Write-Output $masterTaskCmd
Invoke-Expression $masterTaskCmd
#[Console]::ReadKey()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment