How to Run a Bash or PowerShell Script Step in Azure Pipelines
Bash@3 runs a shell script and PowerShell@2 runs PowerShell, each accepting either an inline script or a file path.
Use Bash@3 with targetType: inline (or filePath) for shell, and PowerShell@2 for PowerShell. The script: and pwsh: shorthands map to these tasks for quick steps.
Steps
- Pick
Bash@3for shell orPowerShell@2for PowerShell. - Set
targetType: inlinewithscript, orfilePathfor a file. - Use
failOnStderrto fail the step when the script writes to stderr.
Pipeline
azure-pipelines.yml
steps:
- task: Bash@3
inputs:
targetType: inline
script: |
set -euo pipefail
./build.sh
failOnStderr: true
displayName: Build (bash)
- task: PowerShell@2
inputs:
targetType: inline
script: |
Write-Host "Packaging"
./package.ps1
displayName: Package (pwsh)Gotchas
- The
script:shorthand runs Bash on Linux/macOS and Command Prompt on Windows;bash:forces Bash. - Without
set -ea failing command mid-script may not fail the step. - PowerShell@2 uses Windows PowerShell by default; use
pwsh: truefor PowerShell Core.
Related guides
How to Run on Self-Hosted Agents in Azure PipelinesRoute Azure Pipelines jobs to your own machines with a self-hosted agent pool, naming the pool and using dema…
How to Run the Azure CLI With a Service Connection in Azure PipelinesRun authenticated az commands in Azure Pipelines with the AzureCLI@2 task, passing an azureSubscription servi…