---
title: "Azure Pipelines multi-command script steps hide failures in the middle unless you opt in to fail-fast"
url: "https://www.dariuszparys.com/notes/azure-pipelines-multi-command-steps-hide-failures"
author: "Dariusz Parys"
published: 2026-11-23T00:00:00.000Z
description: "An Azure Pipelines Bash or PowerShell step with several commands still reported success after docker build failed, because both tasks take their result from the exit code of the last command only."
tags:
  - "CI/CD"
  - "PowerShell"
  - "Shell"
---

# Azure Pipelines multi-command script steps hide failures in the middle unless you opt in to fail-fast

## Context

A pipeline step built an image, pruned the build cache and printed disk usage, one command per line. The build failed, but the step stayed green. The error only showed up at a later step that needed the image.

## Insight

Both shell tasks pass or fail on the **last command only** by default.

- **Bash@3 (inline):** the script runs without `set -e`, so a failing command in the middle doesn't stop it. The task's result is the last command's exit code.
- **PowerShell@2 (pwsh):** the default `$ErrorActionPreference = 'Stop'` covers cmdlet errors, not the exit codes of native commands like `docker`. The task only checks `$LASTEXITCODE` once, at the end.

To make a step fail fast, opt in at the top of any step that runs more than one command:

```powershell
# pwsh 7.4+ (current hosted agents)
$PSNativeCommandUseErrorActionPreference = $true
docker build -t "$image" -f Dockerfile .
docker builder prune --all --force | Out-Null
df -h /
```

```bash
set -euo pipefail
docker build -t "$image" -f Dockerfile .
docker builder prune --all --force > /dev/null
df -h /
```

If a command is meant to be best effort, check its exit code yourself instead of relying on the default:

```powershell
docker builder prune --all --force | Out-Null
if ($LASTEXITCODE -ne 0) { Write-Host "##vso[task.logissue type=warning]Prune failed" }
```

A single-command step is fine without this, because the last command is the only command.
