Context
A release workflow deploys Bicep with az deployment group create --name <fixed-name>. Cancelling the workflow run stops the runner, but the deployment it started keeps running in Azure.
Insight
With a fixed deployment name, the next run fails until the leftover deployment completes or expires:
DeploymentActive: The deployment ... cannot be saved, because this would overwrite an existing deployment which is still active.Fix: before deploying, read the existing deployment’s state. If it is not terminal (Succeeded, Failed, Canceled, Deleted), cancel it and poll until it stops. If the cancel fails, read the state again, because the deployment may have just finished.
Only do this when GITHUB_ACTIONS=true and the release workflows share a concurrency group (cancel-in-progress: false). Then any running deployment must be left over from a cancelled run. A local deploy is outside that group and could otherwise cancel a live CI release; locally, let it fail with DeploymentActive.
Snippet (PowerShell)
$name = 'my-env-deploy'$state = az deployment group show -g $rg -n $name --query properties.provisioningState -o tsv 2>$nullif ($env:GITHUB_ACTIONS -eq 'true' -and $state -and $state -notin 'Succeeded','Failed','Canceled','Deleted') { az deployment group cancel -g $rg -n $name do { Start-Sleep 10 $state = az deployment group show -g $rg -n $name --query properties.provisioningState -o tsv } while ($state -notin 'Succeeded','Failed','Canceled','Deleted') # add a timeout}az deployment group create -g $rg -n $name --parameters main.bicepparamAt subscription scope, use az deployment sub show and az deployment sub cancel instead. A cancelled deployment leaves resources partly updated, and the next deploy brings them back in line.
Unblock by hand: az deployment group cancel -g <rg> -n <deployment-name>