Bash task

Azure Pipelines

Use this task to run a Bash script on macOS, Linux, or Windows.

YAML snippet

# Bash
# Run a Bash script on macOS, Linux, or Windows
- task: Bash@3
  inputs:
    #targetType: 'filePath' # Optional. Options: filePath, inline
    #filePath: # Required when targetType == FilePath
    #arguments: # Optional
    #script: '# echo Hello world' # Required when targetType == inline
    #workingDirectory: # Optional
    #failOnStderr: false # Optional
    #noProfile: true # Optional
    #noRc: true # Optional

The Bash task also has a shortcut syntax in YAML:

- bash: # script path or inline
  workingDirectory: #
  displayName: #
  failOnStderr: #
  env:  # mapping of environment variables to add

Arguments

Argument Description
targetType
Type
(Optional) Target script type: File Path or Inline
Default value: filePath
filePath
Script Path
(Required) Path of the script to execute. Must be a fully qualified path or relative to $(System.DefaultWorkingDirectory).
arguments
Arguments
(Optional) Arguments passed to the Bash script.
script
Script
(Required, if Type is inline) Contents of the script
Default value: "# Write your commands here\n\necho 'Hello world'\n"
workingDirectory
Working Directory
(Optional) Specify the working directory in which you want to run the command. If you leave it empty, the working directory is $(Build.SourcesDirectory)
failOnStderr
Fail on standard error
(Optional) If this is true, this task will fail if any errors are written to stderr.
Default value: false
noProfile
Don't load the system-wide startup/initialization files
(Optional) Don't load the system-wide startup file /etc/profile or any of the personal initialization files
noRc
Don't read the ~/.bashrc file
(Optional) If this is true, the task will not process .bashrc from the user's home directory.
Default value: true
env
Environment variables
(Optional) A list of additional items to map into the process's environment.
For example, secret variables are not automatically mapped. If you have a secret variable called Foo, you can map it in like this:
steps:
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: echo $MYSECRET
  env:
    MYSECRET: $(Foo)

This is equivalent to:

steps:
- script: echo $MYSECRET
  env:
    MYSECRET: $(Foo)

The Bash task will find the first Bash implementation on your system. Running which bash on Linux/macOS or where bash on Windows will give you an idea of which one it'll select.

Bash scripts checked into the repo should be set executable (chmod +x). Otherwise, the task will show a warning and source the file instead.

Open source

This task is open source on GitHub. Feedback and contributions are welcome.