Skip to content
Latchkey

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@3 for shell or PowerShell@2 for PowerShell.
  • Set targetType: inline with script, or filePath for a file.
  • Use failOnStderr to 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 -e a failing command mid-script may not fail the step.
  • PowerShell@2 uses Windows PowerShell by default; use pwsh: true for PowerShell Core.

Related guides

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