Skip to content

Commit 895a980

Browse files
committed
Use async for RG deletion
1 parent 6cf1f06 commit 895a980

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

steps/cleanup-resources.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,24 @@ steps:
3131
fi
3232
3333
echo "Delete resource group $RUN_ID"
34-
az group delete --name $RUN_ID --yes
34+
az group delete --name $RUN_ID --yes --no-wait
35+
36+
# Poll until the resource group is fully deleted or timeout after 20 minutes
37+
TIMEOUT=1200
38+
INTERVAL=30
39+
ELAPSED=0
40+
while [ $ELAPSED -lt $TIMEOUT ]; do
41+
if ! az group show --name "$RUN_ID" &>/dev/null; then
42+
echo "Resource group $RUN_ID deleted successfully."
43+
exit 0
44+
fi
45+
echo "Resource group $RUN_ID still exists. Waiting... ($ELAPSED/$TIMEOUT seconds elapsed)"
46+
sleep $INTERVAL
47+
ELAPSED=$((ELAPSED + INTERVAL))
48+
done
49+
50+
echo "##vso[task.logissue type=error;] Resource group $RUN_ID was not deleted within $TIMEOUT seconds."
51+
exit 1
3552
displayName: "Destroy Resource Group"
3653
condition: and(${{ eq(parameters.cloud, 'azure') }}, ne(variables['SKIP_RESOURCE_MANAGEMENT'], 'true'))
3754
env:

0 commit comments

Comments
 (0)