Skip to content

Commit

Permalink
Regularly clean up E2E resource groups (#2814)
Browse files Browse the repository at this point in the history
* Cleanup script + yaml

* Another shot

* Trace

* Prevent trigger
  • Loading branch information
adreed-msft authored Sep 25, 2024
1 parent ec12833 commit 5be6c5e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
30 changes: 30 additions & 0 deletions e2e-cleanup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Set-PSDebug -Trace 1

$rgs = Get-AzResourceGroup -Name azcopy-newe2e-*

$rmTarget = @()

foreach($rg in $rgs) {
if ($rg.Tags)
{
$unixTime = $rg.Tags["creation"]

if ($unixTime) {
$date = (Get-Date 01.01.1970)+[System.TimeSpan]::FromSeconds($unixTime)
if ($date.AddDays(1).CompareTo((Get-Date)) -eq -1) {
$rmTarget = $rmTarget + @($rg)
}
} else {
# If it isn't present, it's considered too old and needs to be deleted.
$rmTarget = $rmTarget + @($rg)
}
} else {
$rmTarget = $rmTarget + @($rg)
}
}

foreach ($rg in $rmTarget) {
$rgn = $rg.ResourceGroupName
Write-Output "Removing $rgn"
Remove-AzResourceGroup -Name $rgn -Force
}
20 changes: 20 additions & 0 deletions e2e-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
trigger: none
pr: none

schedules:
- cron: "0 0 * * *"
displayName: "E2E cleanup (Nightly)"
branches:
include: [ "main" ]
always: true

steps:
- task: AzurePowerShell@5
displayName: Clean up E2E runs
inputs:
azureSubscription: 'e2ecleanup'
ScriptType: 'FilePath'
ScriptPath: 'e2e-cleanup.ps1'
FailOnStandardError: true
pwsh: true
azurePowershellVersion: 'LatestVersion'

0 comments on commit 5be6c5e

Please sign in to comment.