From 6379741ff2db8606d7c69bd51f342632cd7b747b Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Wed, 8 Mar 2023 17:46:09 -0500 Subject: [PATCH] Handle resource group deprovision race condition (#5515) --- eng/scripts/live-test-resource-cleanup.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/eng/scripts/live-test-resource-cleanup.ps1 b/eng/scripts/live-test-resource-cleanup.ps1 index ae86a57cce7..79dcc37a728 100644 --- a/eng/scripts/live-test-resource-cleanup.ps1 +++ b/eng/scripts/live-test-resource-cleanup.ps1 @@ -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 '' 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 + } } } }