แชร์ผ่าน


Bash@3 - Bash v3 task

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

Inputs

targetType - Type
string. Allowed values: filePath (File Path), inline. Default value: filePath.

Targets script type: file path or inline.


filePath - Script Path
string. Required when targetType = filePath.

The path of the script to execute. This must be a fully qualified path or relative to $(System.DefaultWorkingDirectory).


arguments - Arguments
string. Optional. Use when targetType = filePath.

The arguments passed to the shell script. Either ordinal parameters or named parameters.


script - Script
string. Required when targetType = inline. Default value: # Write your commands here.

The contents of the script.


workingDirectory - Working Directory
string.

Specifies 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
boolean. Default value: false.

If this is true, this task will fail if any errors are written to the StandardError stream.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

The bash task has a shortcut in YAML: steps.bash.

steps:
- bash: string # Required as first property. An inline script. 
  ## Other task inputs

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 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

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.

Examples

You can map in variables using the env parameter which is common across all tasks, and is 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)

On macOS or Linux, the example above is equivalent to:

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

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 2.115.0 or greater
Task category Utility