Azure DevOps Services
Use this task to run a Bash script on macOS, Linux, or Windows.
# 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 #bashEnvValue: # 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
|(Optional) Target script type: File Path or Inline
|(Required) Path of the script to execute. Must be a fully qualified path or relative to $(System.DefaultWorkingDirectory).|
|(Optional) Arguments passed to the Bash script.|
|(Required, if Type is inline) Contents of the script
|(Optional) Specify 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
|(Optional) When this input is set to
Set value for
|(Optional) If the related input is specified, the value will be used as the path of a startup file that will be executed before running the script. If the environment variable
Default value: empty string
|(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
steps: - task: Bash@3 inputs: targetType: 'inline' script: echo $MYSECRET env: MYSECRET: $(Foo)
The example above is equivalent to:
steps: - script: echo $MYSECRET env: MYSECRET: $(Foo)
The Bash task will find the first Bash implementation on your system.
which bash on Linux/macOS or
where bash on Windows will give you an idea of which one it will select.
Info about Bash startup files
The Bash task invokes the Bash as a non-interactive, non-login shell. When Bash is started non-interactively, to run a shell script, the Bash looks for the variable
BASH_ENV in the environment, unfolds its value if it appears there, and uses the value as the name of a file to read and execute.
There are several options for defining the
BASH_ENV environment variable in a pipeline. Firstly, it's possible to set the
BASH_ENV environment variable as a pipeline variable. In this case, each instance of the Bash task will try to unfold the value of the
BASH_ENV variable and use its value.
variables: BASH_ENV: "~/.profile" steps: - task: Bash@3 inputs: targetType: 'inline' script: env
Another option is to set
BASH_ENV for one particular instance of the Bash task, there are two ways how this can be done:
The first way is to use the
bashEnvValue task input, see an example for reference:
steps: - task: Bash@3 inputs: targetType: 'inline' script: env bashEnvValue: '~/.profile'
Another way is to set the
BASH_ENV variable as an environment variable for the pipeline task via the
env keyword, for example:
- task: Bash@3 inputs: targetType: 'inline' script: env env: BASH_ENV: '~/.profile'
Note that if the
bashEnvValue input is defined in the Bash task, the pipeline task will override the value of the
BASH_ENV variable with the value from the
bashEnvValue input in a case when the
BASH_ENV environment variable was already defined in the environment.
Bash scripts checked into the repo should be set executable (
Otherwise, the task will show a warning and
source the file instead.
This task is open-source on GitHub. Feedback and contributions are welcome.
Submit and view feedback for