-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regularly clean up E2E resource groups (#2814)
* Cleanup script + yaml * Another shot * Trace * Prevent trigger
- Loading branch information
1 parent
ec12833
commit 5be6c5e
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |