Skip to content

Latest commit

 

History

History
151 lines (113 loc) · 3.27 KB

shell-script.md

File metadata and controls

151 lines (113 loc) · 3.27 KB
title description ms.topic ms.assetid ms.custom ms.date monikerRange
Shell Script task
Execute a bash script when building code in Azure Pipelines and Team Foundation Server (TFS)
reference
8D152C13-0934-4665-8D08-30E2A7841351
seodec18
12/07/2018
>= tfs-2015

Shell Script task

[!INCLUDE temp]

Use this task to run a shell script using bash.

::: moniker range="<= tfs-2018"

[!INCLUDE temp]

::: moniker-end

Demands

sh

::: moniker range="> tfs-2018"

YAML snippet

- task: ShellScript@2
  inputs:
    scriptPath:
    #args: '' # Optional
    #disableAutoCwd: false # Optional
    #cwd: '' # Optional
    #failOnStandardError: false

::: moniker-end

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

Example

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

On the Build tab of a build pipeline, add this task:

:::image type="icon" source="media/shell-script.png" border="false":::


Utility: Shell Script

Run test.bat.

  • Script Path: test.sh

This example also works with release pipelines.

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

FAQ

Where can I learn about Bash scripts?

Beginners/BashScripting to get started.

Awesome Bash to go deeper.

[!INCLUDE include]

[!INCLUDE temp]

[!INCLUDE temp]

::: moniker range="< azure-devops"

[!INCLUDE temp]

::: moniker-end