Run Python script
Runs Python 3 source and captures what it prints.
Run Python script
Details #
Sends script to python3 - (found with /usr/bin/env) on standard input. What the program prints to standard output is the step's output, with trailing newlines removed, and goes into into if set. The output object has stdout, exit and, if any, stderr. An exception or non-zero exit fails the step with the first 300 characters of standard error.
To pass structured data out, print(json.dumps(...)) and read the text in a later step.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
script | text | Yes | Required. Python 3 source. | |
into | text | The variable that receives the printed text. | ||
sample | any value | What into holds during a dry run. | ||
timeout | number | Seconds before the step is cancelled. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
- Run Python script “print(sum(range(1, 11)))”
- Show “Total: {{total}}”
Gotchas #
Needs Python 3. It uses whichever
python3the environment finds first. If none is installed the step fails; install Python or the Xcode command line tools.Dry run. Not run:
intogetssampleor an empty string.Timeout. Cancelled after 10 s by default; set
timeoutfor longer jobs.{{ }}values are pasted into the source before it runs, so quote untrusted text carefully. Do not store secrets in the script text.