---
title: "Azure CLI --no-wait discards the command result, so az acr build --no-wait prints no run ID"
url: "https://www.dariuszparys.com/notes/azure-cli-no-wait-discards-acr-run-id"
author: "Dariusz Parys"
published: 2026-11-30T00:00:00.000Z
description: "A script that read the run ID from az acr build --no-wait got empty output, because Azure CLI discards the result of any command run with --no-wait and prints the ID only as a warning on stderr."
tags:
  - "Azure"
  - "Azure CLI"
  - "CI/CD"
  - "Docker"
  - "PowerShell"
---

# Azure CLI --no-wait discards the command result, so az acr build --no-wait prints no run ID

## Context

A release script queued an image build in Azure Container Registry and wanted the run ID, so it could wait for that exact run and take the image digest from it:

```powershell
$run = az acr build --registry <registry> --image <repo>:<tag> . --no-wait --output json | ConvertFrom-Json
$run.runId   # expected the queued run
```

Every build failed with "returned no run ID". The builds themselves were queued and ran.

## Insight 1: `--no-wait` prints no result

With `--no-wait`, the command exits 0 and writes **nothing to stdout**. The run ID appears only in a warning on stderr (`Queued a build with ID: <id>`), which is a log line, not output.

To get the run from the command that queued it, use `--no-logs` instead. The CLI then waits for the run and returns it:

```powershell
$run = az acr build --registry <registry> --image <repo>:<tag> . --no-logs --output json | ConvertFrom-Json
$run.runId
$run.status                   # Succeeded
$run.outputImages[0].digest   # sha256:...
az acr task logs --registry <registry> --run-id $run.runId   # the log is not streamed with --no-logs
```

A run that does not succeed exits 1 with empty stdout. Only the error text names it: `The run with ID '<id>' finished with unsuccessful status ...`.

> **Documented:** the `az acr` reference says `--no-wait` makes `az acr build` / `az acr run` return immediately after queuing, and that `--no-logs` suppresses the logs. A signing tutorial shows by example that `az acr build ... --no-logs --query "outputImages[0].digest" -o tsv` yields the digest. ([az acr reference](https://learn.microsoft.com/en-us/cli/azure/acr?view=azure-cli-latest), [sign, build and push tutorial](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tutorial-sign-build-push))
>
> **Observed (2026-11-30, Azure CLI 2.88.0):** no page says that `--no-wait` drops the result. In a CI run, `az acr build --no-wait --output json` exited 0 with empty stdout. `--no-logs --output json` returned the finished run with `runId`, `status` and `outputImages` for `az acr build`, and the run with its `runId` for a two-image `az acr run`; `az acr task show-run` then listed one digest per image. A failing build and a failing run both exited 1 with no JSON.
>
> **Read in the CLI source, not tested beyond ACR:** the discard is in the CLI core, not in the `acr` module. `_run_job` sets the result to `None` for any command that supports `--no-wait` when the flag is passed, so the same should hold for every such command.

## Insight 2: the fake CLI printed what the real one never prints

The script had tests, and they passed. The stand-in `az` used by the tests answered the `--no-wait` call with `{"runId":"run1","status":"Queued"}`. It was written from the output the author expected, so the tests proved the script against an assumption.

What would have caught it:

- Capture the real command once for each flag combination the code relies on: stdout, stderr and exit code, for success and for failure. Build the fake from that capture.
- Keep stdout and stderr apart in the fake. Here the ID was real, but on the wrong stream.
- After correcting a fake, run the suite against the old code first. It must fail with the production error. If it stays green, the fake still differs from the real tool.
