Updated on 2024-05-29 GMT+08:00

Expressions

An expression can be any combination of contexts, operators, functions, or literals. You can use an expression as the execution condition to control job execution. Contexts can be accessed programmatically with expressions, so information such as pipeline runs, sources, variables, and jobs can be transferred within a pipeline.

Operator

Operator

Description

.

Attribute reference

!

False

==

Equal

!=

Not equal

&&

And

||

Or

Example

If the current job is executed regardless of whether the previous job (ID: job_1) succeeded or failed, the expression can be as follows:

${{ jobs.job_1.status == 'COMPLETED' || jobs.job_1.status == 'FAILED' }}

Functions

The following functions can be used in expressions:

  • contains
    • Format

      contains(search, item)

    • Description

      If search contains item, this function returns true. If search is an array, this function returns true if the item is an element in the array. If search is a string, this function returns true if the item is a substring of search.

    • Example

      contains('abc', 'bc') returns true.

  • startsWith
    • Format

      startsWith(searchString, searchValue)

    • Description

      If searchString starts with searchValue, this function returns true.

    • Example

      startsWith('abc', 'ab') returns true.

  • endsWith
    • Format

      endsWith(searchString, searchValue)

    • Description

      If searchString ends with searchValue, this function returns true.

    • Example

      endsWith('abc', 'bc') returns true.

  • Object filter

    You can use the * syntax to apply a filter and select matching items in a collection.

    Example

    The following is the context of jobs execution.

    The filter jobs.*.status returns ['COMPLETED', 'FAILED'].

    Filters can be used together with the contains function. For the following case, contains(jobs.*.status, 'FAILED') will return true.

    {
        "check_job": {
            "status": "COMPLETED",
            "metrics": {
                "critical": "0",
                "major": "0"
            }
        },
        "demo_job": {
            "status": "FAILED"
        }
    }