Skip to content

Commit

Permalink
Handle resource group deprovision race condition (#5515)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbp authored Mar 8, 2023
1 parent 94e9310 commit 6379741
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion eng/scripts/live-test-resource-cleanup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,18 @@ function FindOrCreateDeleteAfterTag {
$deleteAfter = [datetime]::UtcNow.AddHours($DeleteAfterHours)
if ($Force -or $PSCmdlet.ShouldProcess("$($ResourceGroup.ResourceGroupName) [DeleteAfter (UTC): $deleteAfter]", "Adding DeleteAfter Tag to Group")) {
Write-Host "Adding DeleteAfter tag with value '$deleteAfter' to group '$($ResourceGroup.ResourceGroupName)'"
$ResourceGroup | Update-AzTag -Operation Merge -Tag @{ DeleteAfter = $deleteAfter }
$result = ($ResourceGroup | Update-AzTag -Operation Merge -Tag @{ DeleteAfter = $deleteAfter }) 2>&1
if ("Exception" -in $result.PSObject.Properties.Name) {
# Handle race conditions where the group starts deleting after we get its info, in order to avoid pipeline warning/failure emails
# "The resource group '<group name>' is in deprovisioning state and cannot perform this operation"
if ($result.Exception.Message -notlike '*is in deprovisioning state*') {
Write-Error $result.Exception.Message
} else {
Write-Host "Skipping '$($ResourceGroup.ResourceGroupName)' as it is in a deprovisioning state"
}
} else {
$result
}
}
}
}
Expand Down

0 comments on commit 6379741

Please sign in to comment.