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: falseNotes
- 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
How to Publish Pipeline Artifacts in Azure PipelinesPersist build outputs in Azure Pipelines with the PublishPipelineArtifact task so later jobs and stages can d…
How to Use a Template with Parameters in Azure PipelinesReuse pipeline logic in Azure Pipelines by defining a parameterized template and passing typed parameters whe…