ShellScript@2 - Shell script v2 task

Use this task to run a shell script using bash.

Syntax

# Shell script v2
# Run a shell script using Bash.
- task: ShellScript@2
  inputs:
    scriptPath: # string. Required. Script Path. 
    #args: # string. Arguments. 
  # Advanced
    #disableAutoCwd: false # boolean. Specify Working Directory. Default: false.
    #cwd: # string. Optional. Use when disableAutoCwd = true. Working Directory. 
    #failOnStandardError: false # boolean. Fail on Standard Error. Default: false.
# Shell Script v2
# Run a shell script using bash.
- task: ShellScript@2
  inputs:
    scriptPath: # string. Required. Script Path. 
    #args: # string. Arguments. 
  # Advanced
    #disableAutoCwd: false # boolean. Specify Working Directory. Default: false.
    #cwd: # string. Optional. Use when disableAutoCwd = true. Working Directory. 
    #failOnStandardError: false # boolean. Fail on Standard Error. Default: false.

Inputs

scriptPath - Script Path
string. Required.

Specifies the relative path from the repo root to the shell script file that you want to run.


args - Arguments
string.

Specifies the arguments that you want to pass to the script.


disableAutoCwd - Specify Working Directory
boolean. Default value: false.

Specifies the working directory where the task runs the script. If the value is left empty, the task defaults to the folder where the script is located.


cwd - Working Directory
string. Optional. Use when disableAutoCwd = true.

Specifies the working directory where the script is run. If the value is left empty, the task uses the root of the repo (build) or artifacts (release), which is $(System.DefaultWorkingDirectory).


failOnStandardError - Fail on Standard Error
boolean. Default value: false.

If the value is true, the task will fail if 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

Where can I learn about Bash scripts?

How do I set a variable so that it can be read by subsequent scripts and tasks?

To learn more about defining build variables in a script, see Define and modify your build variables in a script.

To learn more about defining release variables in a script, see Define and modify your release variables in a script

Examples

Create test.sh at the root of your repo. We recommend creating this file from a Linux environment (such as a real Linux machine or Windows Subsystem for Linux) so that line endings are correct. Also, don't forget to chmod +x test.sh before you commit it.

#!/bin/bash
echo "Hello World"
echo "AGENT_WORKFOLDER is $AGENT_WORKFOLDER"
echo "AGENT_WORKFOLDER contents:"
ls -1 $AGENT_WORKFOLDER
echo "AGENT_BUILDDIRECTORY is $AGENT_BUILDDIRECTORY"
echo "AGENT_BUILDDIRECTORY contents:"
ls -1 $AGENT_BUILDDIRECTORY
echo "SYSTEM_HOSTTYPE is $SYSTEM_HOSTTYPE"
echo "Over and out."

Add the following task to your pipeline to run the previous script.

- task: ShellScript@2
  inputs:
    scriptPath: 'test.sh'

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands Self-hosted agents must have capabilities that match the following demands to run jobs that use this task: sh
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version All supported agent versions.
Task category Utility