Shell Script task
Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015
Use this task to run a shell script using bash.
In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.
- task: ShellScript@2 inputs: scriptPath: #args: '' # Optional #disableAutoCwd: false # Optional #cwd: '' # Optional #failOnStandardError: false
|Script Path||Relative path from the repo root to the shell script file that you want to run.|
|Arguments||Arguments that you want to pass to the script.|
|Working Directory||Working directory in which you want to run the script. If you leave it empty it is folder where the script is located.|
|Fail on Standard Error||Select if you want this task to fail if any errors are written to the StandardError stream.|
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."
On the Build tab of a build pipeline, add this task:
This example also works with release pipelines.
This task is open source on GitHub. Feedback and contributions are welcome.
Where can I learn about Bash scripts?
Beginners/BashScripting to get started.
Awesome Bash to go deeper.
How do I set a variable so that it can be read by subsequent scripts and tasks?
Q: I'm having problems. How can I troubleshoot them?
A: Try this:
On the variables tab, add
system.debugand set it to
true. Select to allow at queue time.
In the explorer tab, view your completed build and click the build step to view its output.
The control options arguments described above can also be useful when you're trying to isolate a problem.
Q: How do variables work? What variables are available for me to use in the arguments?
$(Agent.BuildDirectory) are just a few of the variables you can use.
Variables are available in expressions as well as scripts; see variables to learn more about how to use them.
There are some predefined build and release variables you can also rely on.
Do I need an agent?
You need at least one agent to run your build or release.
I'm having problems. How can I troubleshoot them?
I can't select a default agent pool and I can't queue my build or release. How do I fix this?
See Agent pools.