Skip to main content

Run a script

The Run Script job runs an embedded PowerShell, Bash, Python, or Shell script on the agent. Use it instead of Run Command when the logic is more than a single command line. It's built in, so there's nothing to set up.

What this solves

A step needs real logic: several commands, a loop, a conditional. Kept in a separate script file on some server, that logic drifts from the job and no one remembers where it lives or what it assumes.

Use it when​

  • Your step needs several commands, conditionals, or loops.
  • You want to keep the script with the job rather than as a separate file.

Add a Run Script job to a workflow​

To add a Run Script job, complete the following steps:

  1. Go to Workflows and open the workflow you want to edit.
  2. Add a job: on an empty workflow select First Job, otherwise select New Job from the Job Tools panel.
  3. In the job editor, select the Job Definition tab.
  4. Select Show Job Types.
  5. In the job type catalog, under Script, select Run Script.
  6. Under Job Parameters, choose the Script Type and enter your Script Content.
  7. Set any optional settings (see below).
  8. Select Save & Close.

Settings​

SettingNotes
Script TypePowerShell, Bash, Python, or Shell. Shell is the default.
Script ContentThe script to run. Required.
Script ArgumentsArguments passed to the script.
Working DirectoryWhere the script runs. Defaults to the agent's working directory.
Environment VariablesExtra environment variables for the script.
Fail on ErrorOn by default: a non-zero exit code fails the job. Turn off and the exit code never fails it.
Exit CriteriaUp to five exit-code conditions that mark the job failed. Set any and Fail on Error no longer applies.
Output ParsingUp to five rules that search the job output for text and set an exit code, which the exit criteria then judge.
Good to know
  • The interpreter your script uses must be installed on the agent — PowerShell 7 (pwsh) on Linux/macOS, Python, or Bash. Shell is the exception: it is always available. If a script won't start, confirm the interpreter with your administrator.
  • PowerShell scripts run without your profile and with execution policy bypassed. Make the script self-contained rather than relying on a console's setup.
  • Like Run Command, scripts can't read the agent's stored secrets from the environment. Pass what you need as Environment Variables or use a connection-based connector.
  • Exit Criteria and Output Parsing are available here too, and work exactly as they do on Run a command. But a script you own can just call exit 8 — reach for them when the script is one you can't change, or when the signal is only in its output.
  • A job the platform stops — a timeout, or a cancel — always fails, whatever your exit criteria say.

Related topics