Utility: Shell script

Last Update: 9/26/2016

Team Services | TFS 2017 | TFS 2015 | Previous versions (XAML builds)

icon Run a shell script using bash

Demands

sh

Arguments

Argument Description
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.
Advanced
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 step to fail if any errors are written to the StandardError stream.
Control options

Example

Create test.sh at the root of your repo:

#!/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 "BUILD_SOURCESDIRECTORY is $BUILD_SOURCESDIRECTORY"
echo "BUILD_SOURCESDIRECTORY contents:"
ls -1 $BUILD_SOURCESDIRECTORY
echo "Over and out."

On the Build tab of a build definition, add this step:


Utility: Shell Script

Run test.bat.

  • Script Path: test.sh

Q&A

Where can I learn about Bash scripts?

Beginners/BashScripting to get started.

Awesome Bash to go deeper.

Q: I'm having problems. How can I troubleshoot them?

A: Try this:

  1. On the variables tab, add system.debug and set it to true. Select to allow at queue time.

  2. 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?

A: $(Build.SourcesDirectory) and $(Agent.BuildDirectory) are just a few of the variables you can use. See Variables.

Do I need a build agent?

You need at least one agent to run your build. Get an agent.

I can't select a default agent queue and I can't queue my build. How do I fix this?

See queues.

I use Team Foundation Server on-premises and I don't see some of these features. Why not?

Some of these features are available only on Visual Studio Team Services and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.