Templating

Atkins uses expr-lang for conditional expressions in if: fields.

Expression Syntax

Expressions are evaluated as boolean conditions:

  if: version > 1
if: env == "production"
if: enabled == true

Available Variables

All pipeline and job variables are available in expressions:

  name: Expression Variables

vars:
  version: 2
  env: production
  enabled: true

jobs:
  check:
    aliases: [default]
    steps:
      - if: version > 1
        run: echo "Version is greater than 1"

      - if: env == "production"
        run: echo "Running in production"

      - if: enabled
        run: echo "Feature is enabled"

Operators

Comparison

Operator Description
== Equal
!= Not equal
> Greater than
< Less than
>= Greater or equal
<= Less or equal

Logical

Operator Description
&& Logical AND
`
! Logical NOT

String

Operator Description
s contains substr Check substring
s startsWith prefix Check prefix
s endsWith suffix Check suffix

Examples

  name: Expression Operators

vars:
  total: 5
  name: "hello-world"
  active: true

jobs:
  examples:
    aliases: [default]
    steps:
      - if: total >= 5
        run: echo "Count is at least 5"

      - if: total != 0
        run: echo "Count is not zero"

      - if: name contains "world"
        run: echo "Name contains world"

      - if: name startsWith "hello"
        run: echo "Name starts with hello"

      - if: '!active'
        run: echo "This is skipped"

Complex Expressions

  name: Complex Expressions

vars:
  env: production
  version: 3
  deploy: true

jobs:
  conditional:
    aliases: [default]
    steps:
      - if: env == "production" && version >= 2
        run: echo "Production v2+"

      - if: env == "staging" || env == "production"
        run: echo "Non-development environment"

      - if: deploy && version > 1
        run: echo "Deploying version ${{ version }}"

Truthiness

  • Empty strings are falsy
  • Zero is falsy
  • false is falsy
  • Everything else is truthy

See Also