Expression syntax
apolo-flow
allows writing custom expressions in YAML configuration files.
About contexts and expressions
You can use expressions to programmatically set variables in workflow files and access contexts. An expression can be any combination of literal values, references to a context, or functions. You can combine literals, context references, and functions with the help of operators.
You need to use specific syntax to tell Apolo Flow to evaluate an expression rather than to treat it as a string.
Example - setting an environment variable:
Sometimes curly brackets conflict with other tools in your toolchain. For example, cookiecutter
uses Jinja2
templates which also uses curly brackets for template formatting.
In this case, apolo-flow
accepts the square brackets syntax for expressions: $[[ <expression> ]]
. Both notations are equal and interchangeable.
Contexts
Contexts are a way to access information about workflow runs, jobs, tasks, volumes, images, etc. Contexts use the expression syntax.
There are two main sets of contexts: one is available for live mode and another one for batch mode. Additionally, actions can access a specific namespace with contexts that are similar but slightly different from ones from the main workflow. The following chapters describe all mentioned context namespaces in detail. Refer to live contexts, batch contexts, and actions contexts for details.
Property access
You can access properties of contexts and other objects using one of the following syntaxes:
Index syntax:
flow['workspace']
Property dereference syntax:
flow.workspace
In order to use property dereference syntax, the property name must:
start with a letter
a-Z
.be followed by a letter
a-Z
, digit0-9
or underscore_
.
Literals
As part of an expression, you can use None
, bool
, int
, float
, or string
data types.
None
None
boolean
True
or False
(case sensitive).
int
Any integer defined by either decimal (42
), hex (0xFF
), octal (0o22
), or binary
(0b1011
) format.
float
A real number that contains digits after the period. Exponential notation is also supported.
string
You can use either single or double quotes for strings.
Example
Operators
( )
Logical grouping
not
Not
<
Less than
<=
Less than or equal
>
Greater than
>=
Greater than or equal
==
Equal
!=
Not equal
and
And
or
Or
Lists and dictionaries
You can use lists and dictionaries in expressions.
Example
Functions
To allow some operations in expressions, Apolo provides a set of built-in functions. The function call syntax is the following:
When a function returns an object as the result, you can access properties as usual:
Check the functions reference for the list of available functions.
Last updated