---
title: "Cancelling a GitHub Actions run leaves its ARM deployment running in Azure"
url: "https://www.dariuszparys.com/notes/cancelled-github-actions-run-leaves-arm-deployment-running"
author: "Dariusz Parys"
published: 2026-11-09T00:00:00.000Z
description: "Cancelling a workflow run stops the runner but not the ARM deployment it started, so the next run with the same deployment name fails with DeploymentActive."
---

# Cancelling a GitHub Actions run leaves its ARM deployment running in Azure

## 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)

```powershell
$name = 'my-env-deploy'
$state = az deployment group show -g $rg -n $name --query properties.provisioningState -o tsv 2>$null
if ($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.bicepparam
```

At 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>`
