LabBuilder - CleanUp #111
This file contains hidden or 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
name: "LabBuilder - CleanUp" | |
on: | |
workflow_dispatch: | |
workflow_call: | |
permissions: | |
id-token: write | |
jobs: | |
removeResources: | |
name: "Remove LabBuilder resources" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Azure Login | |
id: login | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Cleanup | |
uses: azure/CLI@v1 | |
with: | |
inlineScript: | | |
echo "Searching for resource groups tagged with LabBuilder=validation..." | |
resourceGroups=$(az group list --tag LabBuilder=validation --query "[].name" -o tsv) | |
if [ -z "$resourceGroups" ]; then | |
echo "No resource groups found to delete. Exiting." | |
exit 0 | |
fi | |
echo "Found resource groups to delete:" | |
echo "$resourceGroups" | |
# Issue all deletes in parallel with --no-wait | |
for rg in $resourceGroups; do | |
echo "Deleting resource group: $rg..." | |
az group delete --name "$rg" --yes --no-wait & | |
done | |
wait | |
echo "All delete commands issued with --no-wait. Cleanup step complete." | |