Muokkaa

Jaa


Bash@3 - Bash v3 task

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

Syntax

# Bash v3
# Run a Bash script on macOS, Linux, or Windows.
- task: Bash@3
  inputs:
    #targetType: 'filePath' # 'filePath' | 'inline'. Type. Default: filePath.
    filePath: # string. Required when targetType = filePath. Script Path. 
    #arguments: # string. Optional. Use when targetType = filePath. Arguments. 
    #script: # string. Required when targetType = inline. Script. 
  # Advanced
    #workingDirectory: # string. Working Directory. 
    #failOnStderr: false # boolean. Fail on Standard Error. Default: false.
    #bashEnvValue: # string. Set value for BASH_ENV environment variable.
# Bash v3
# Run a Bash script on macOS, Linux, or Windows.
- task: Bash@3
  inputs:
    #targetType: 'filePath' # 'filePath' | 'inline'. Type. Default: filePath.
    filePath: # string. Required when targetType = filePath. Script Path. 
    #arguments: # string. Optional. Use when targetType = filePath. Arguments. 
    #script: # string. Required when targetType = inline. Script. 
  # Advanced
    #workingDirectory: # string. Working Directory. 
    #failOnStderr: false # boolean. Fail on Standard Error. Default: false.
    #noProfile: true # boolean. Don't load the profile startup/initialization files. Default: true.
    #noRc: true # boolean. Don't read the `~/.bashrc' initialization file. Default: true.
# Bash v3
# Run a Bash script on macOS, Linux, or Windows.
- task: Bash@3
  inputs:
    #targetType: 'filePath' # 'filePath' | 'inline'. Type. Default: filePath.
    filePath: # string. Required when targetType = filePath. Script Path. 
    #arguments: # string. Optional. Use when targetType = filePath. Arguments. 
    #script: # string. Required when targetType = inline. Script. 
  # Advanced
    #workingDirectory: # string. Working Directory. 
    #failOnStderr: false # boolean. Fail on Standard Error. Default: false.

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\n\necho 'Hello world'.

The contents of the script.


script - Script
string. Required when targetType = inline. Default value: # Write your commands here\n\n# Use the environment variables input below to pass secret variables to this script.

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.


bashEnvValue - Set value for BASH_ENV environment variable
string.

If the input is specified, its value is expanded and used as the path of a startup file to execute before running the script. If the environment variable BASH_ENV has already been defined, the task will override this variable only for the current task. Learn more about Bash Startup Files.


noProfile - Don't load the profile startup/initialization files
boolean. Default value: true.

Don't load the system-wide startup file /etc/profile or any of the personal initialization files.


noRc - **Don't read the ~/.bashrc' initialization file**<br> boolean. Default value: true`.


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.

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

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