Skip to content
Latchkey

How to Run a Script Step with Bash in Azure Pipelines

The Bash@3 task runs your script under bash with proper error propagation.

Use the Bash@3 task with an inline script for portable shell logic. failOnStderr is optional; bash already fails the step on a non-zero exit by default.

An inline bash step

Read a pipeline variable with the $(Var) macro and run multi-line bash.

azure-pipelines.yml
steps:
  - task: Bash@3
    displayName: 'Run migration'
    inputs:
      targetType: 'inline'
      script: |
        set -euo pipefail
        echo "Deploying $(Build.BuildNumber)"
        ./migrate.sh --env "$(TARGET_ENV)"
      failOnStderr: false

Notes

  • set -euo pipefail makes the script fail fast on errors and unset variables.
  • Azure macro syntax $(Var) is fine to use directly; it is expanded by the agent before bash runs.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →