Expression language
This page is the reference for the expression language used in workflow YAML and, for its own inputs, in a task definition's exec.
Template syntax
An expression is embedded in a YAML string value using the ${{...}} delimiter:
args:
message: Hello, ${{inputs.name}}!
verbose: ${{inputs.log_level == 'debug'}}
The platform evaluates every ${{...}} block when the task starts and replaces it with the result, written as text: null becomes an empty string, a boolean becomes true or false, and an array or object becomes compact JSON. Text outside the delimiters passes through unchanged.
An expression that does not parse, such as one with a syntax error or one that calls a function that does not exist or with the wrong number of arguments, is refused when the workflow or task definition holding it is uploaded or imported, and the error names the value and what is wrong; for a workflow, see Upload checks. An expression that parses but cannot be evaluated when its task starts, such as one that gives fromJSON text that is not JSON, fails that task, and its failure reason and execution log name the value and the error.
Data access
Every value an expression reads from these namespaces is text: run inputs, secrets, environment variables and task outputs alike. An input set to false holds the text false, and an output holding a JSON array stays a string until you read it with fromJSON.
Run inputs
inputs.<name>
Resolves to the value of the named run input. Returns null if the input was not supplied and has no default.
Secrets
secrets.<name>
Resolves to the value of the named secret.
When a task starts, the platform resolves secrets.<name> in this order:
- A project secret with that name in the run's project.
- Otherwise, an account secret with that name whose allowed projects include the run's project.
- Otherwise, null, so the argument receives an empty value. A missing secret does not stop the run.
secrets.WORKFLOW_TOKEN is the platform's own addition to this namespace: a credential scoped to the current run, which a task can use to read the run's project and to push its results there. Pass it to a task the same way you pass any other secret:
push:
name: Push
args:
token: ${{secrets.WORKFLOW_TOKEN}}
Workflow run token
lists what it can reach and how long it is accepted. Because the WORKFLOW_ prefix is reserved, you
cannot create a secret of your own beginning with it.
Run environment variables
env.<name>
Resolves to the value of a run environment variable. Two kinds of name live here: variables carried by the run itself — including any an earlier task exported, see Exporting environment variables, though a task that declares terminate_on exports nothing — and the platform's two storage variables, env.WORKFLOW_STORAGE and env.WORKFLOW_TASK_STORAGE:
args:
source: ${{env.WORKFLOW_STORAGE}}/incoming
This is the supported way to hand a task a path inside the run's shared workspace without hardcoding it. See Runtime storage.
Where env resolves depends on what is being resolved:
| Location | What env resolves |
|---|---|
A workflow step's task args or image_credentials | Run environment variables, plus WORKFLOW_STORAGE and WORKFLOW_TASK_STORAGE |
An if condition or for_each items list | Run environment variables, plus WORKFLOW_STORAGE |
A task definition's own exec.args/exec.env | Nothing — exec resolves its declared inputs only |
The other variables a task container receives are set on the container and are not in the env expression namespace; see Environment variables. A task definition's exec resolves its declared inputs only; see What resolves inside exec.
Task outputs
tasks.<task_key>.outputs.<output_name>
Resolves to the named output of a task this task waits on, once that task has finished. A task can read the outputs of:
- the tasks it lists in
start_on, the tasks those list, and so on; - inside the block of an if or
for_eachtask, the tasks that if orfor_eachtask waits on, by the same rule, at every level of nesting.
Inside the block of a for_each task, each iteration reads its own copies of the block's tasks, never another iteration's. Every other output resolves to null:
- a task with no
start_onpath to it from this task or from an if orfor_eachtask around this one, even one that finished before this task started; - a task inside the block of an if or
for_eachtask, read from outside that block, including by a task that waits on that if orfor_eachtask; - a task that wrote no output by that name.
blocks:
main:
tasks:
fetch:
name: Fetch
lint:
name: Lint
loop:
name: Loop
start_on:
- fetch
for_each:
items: ${{tasks.fetch.outputs.files}}
block: per_file
per_file:
tasks:
download:
name: Download
args:
file: ${{tasks.loop.for_each.item}}
convert:
name: Convert
start_on:
- download
args:
input: ${{tasks.download.outputs.path}}
format: ${{tasks.fetch.outputs.format}}
Here convert reads its own iteration's download, which it waits on, and fetch, which loop waits on. ${{tasks.lint.outputs.report}} would resolve to null in convert, even if lint finished before the loop started, because neither convert nor loop waits on lint. No task after loop can read download or convert.
To use a value from inside a block after its if or for_each task, export it as an environment variable instead.
An output is text; read an array or object from it with fromJSON.
A task that declares terminate_on has no outputs, since what it writes is discarded; see Tasks that declare terminate_on. Uploading or importing a workflow that reads them as tasks.<task_key>.outputs is refused (see Upload checks), and a read the check does not see, such as one that names the task by index access, tasks['<task_key>'], resolves to null. Reach such a task at its runner address instead.
Runner address
tasks.<task_key>.ip-address
Resolves to the IP address of a task that declares terminate_on, while it is running. Such a task keeps running alongside the tasks that wait on it, so those tasks can use the address to reach a service it starts:
blocks:
main:
tasks:
db:
name: Database
terminate_on:
- migrate
migrate:
name: Migrate
start_on:
- db
args:
database_host: ${{tasks.db.ip-address}}
The tasks of a run can reach each other on these addresses; nothing outside the run can. The tasks that can read a task's address are those that could read an ordinary task's outputs: the tasks that wait on it, directly or through other tasks, and, inside an if or block of a for_each task, the tasks the enclosing if or for_each task waits on. It resolves to null once the task has stopped, and for a task that does not declare terminate_on.
For Each loop variables
tasks.<for_each_task_key>.for_each.item
tasks.<for_each_task_key>.for_each.index
tasks.<for_each_task_key>.for_each.item is the current element from the for_each task's items list, and tasks.<for_each_task_key>.for_each.index is its zero-based position. Both are available only inside the block a for_each task iterates, including blocks nested inside it. <for_each_task_key> is the for_each task's key under tasks.
item is text: a string element as written, and any other element as its JSON. Read a field of an object element with fromJSON(tasks.<for_each_task_key>.for_each.item).<field>.
Operators
Operators are listed from highest to lowest precedence. Operators in the same row have the same precedence and apply left to right. Use parentheses to group, as in (a || b) && c.
| Operator | Description |
|---|---|
., [ ], function calls | Property access and index access, described below, and calls to the expression functions |
! | Logical NOT: true when the operand is falsy, otherwise false |
<, <=, >, >= | Numeric comparison |
==, != | Equal, not equal |
&& | Logical AND: the left operand when it is falsy, otherwise the right operand |
|| | Logical OR: the left operand when it is truthy, otherwise the right operand |
There are no arithmetic or string-concatenation operators. Build a string with format.
Comparison reads both sides as numbers: a string as the number it spells, with an empty string as 0, null as 0, and true and false as 1 and 0. When either side cannot be read as a number, such as the string 'abc' or an array, the comparison is false.
Equality compares two values of the same type directly, ignoring letter case when both are strings. Values of different types are compared as numbers, as above, so '1' == 1 is true while 'true' == true is false. Because inputs and outputs are text, compare them with text, as in inputs.dry_run == 'true'.
&& and || return one of their operands rather than a boolean, and skip the right operand when the left one decides the result. inputs.owner || 'unassigned' gives a default for an input that is falsy: empty, not supplied, 0 or false.
Literals
| Literal | Example | Notes |
|---|---|---|
| String | 'hello' | Single quotes only. Write '' for a quote inside, as in 'it''s'. A double-quoted string is a syntax error. |
| Number | 42, -1, 3.14, 1e3 | Integer and floating-point |
| Boolean | true, false | Case-insensitive |
| Null | null | Case-insensitive |
Property access
Use . to access a named property on an object:
tasks.fetch_step.outputs.file_path
A name can contain letters, digits, _ and -, and starts with a letter or _. A missing property, or a property of a value that is not an object, gives null.
Index access
Use [n] to access an element of an array by zero-based index. A task output is text, so read the array from it with fromJSON first:
fromJSON(tasks.list_step.outputs.items)[0]
An index outside the array gives null. On an object, [ ] reads the property whose name its value spells, which also reaches names . cannot:
fromJSON(tasks.fetch_step.outputs.sizes)[inputs.region]
Property and index access can be chained:
fromJSON(tasks.list_step.outputs.records)[2].name
Truthiness
A value is truthy unless it is one of:
falsenull- the number
0 - the strings
''(empty) and'0', and'false'and'NaN'in any letter case
Every other value is truthy, including an empty array or object. Because inputs and outputs are text, an input set to false or 0 is falsy.
Truthiness decides the result of !, && and ||, and decides an if condition. An if condition is judged on the text it renders to, by the same rule, so wrap the expression in ${{...}}: without it, inputs.enabled is the plain text inputs.enabled, which is truthy.