Bash task

Azure Pipelines

Use this task in a build or release pipeline 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

ArgumentDescription
TypeSets whether this is an inline script or a path to a .sh file
File pathPath of the script to execute. Must be a fully qualified path or relative to $(System.DefaultWorkingDirectory). Required if Type is filePath.
ArgumentsArguments passed to the Bash script.
ScriptContents of the script. Required if Type is inline
Working DirectorySpecify the working directory in which you want to run the command. If you leave it empty, the working directory is $(Build.SourcesDirectory).
Fail on standard error If this is true, this task will fail if any errors are written to stderr.
Don't load the profile/initialization files If this is true, the task will skip loading the system-wide startup file /etc/profile and any user-level profile initialization files.
Don't read the ~/.bashrc file If this is true, the task will not process .bashrc from the user's home directory.
Environment variables 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)
Control options

Open source

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