Step Conditions

The Pipeline CI/CD supports the defining of conditional pipeline steps by the when block. If all conditions in the when block are evaluated to be true, then the step is executed, otherwise it is skipped.

Here's an example of a conditional execution:

pipeline:
  slack:
    image: plugins/slack
    channel: dev
+   when:
+     branch: master

The step will now trigger on master, but only if the target branch of a pull request is also master. You can add an event condition to further limit pushes to master.

Branches

Execute a step if the branch is master or develop:

when:
  branch: [master, develop]

Execute a step if the branch starts with prefix/*:

when:
  branch: prefix/*

Execute a step using custom include and exclude logic:

when:
  branch:
    include: [ master, release/* ]
    exclude: [ release/1.0.0, release/1.1.* ]

Events

Execute a step if the build event is a tag:

when:
  event: tag

Execute a step if the build event is a tag created from the specified branch:

when:
  event: tag
+ branch: master

Execute a step for all non-pull request events:

when:
  event: [push, tag, deployment]

Execute a step for all build events:

when:
  event: [push, pull_request, tag, deployment]

Tags

Execute a step if the tag name starts with release:

when:
  tag: release*

Status

Execute a step when the build status changes:

when:
  status: changed

Execute a step when the build succeeds or fails:

when:
  status:  [ failure, success ]

Platform

Execute a step for a specific platform:

when:
  platform: linux/amd64

Execute a step for a specific platform using wildcards:

when:
  platform:  [ linux/*, windows/amd64 ]

Environment

Execute a step for deployment events matching the target deployment environment:

when:
  environment: production
  event: deployment

Matrix

Execute a step for a single matrix permutation:

when:
  matrix:
    GO_VERSION: 1.5
    REDIS_VERSION: 2.8

Instance

Execute a step only on a certain Pipeline CI/CD instance:

when:
  instance: stage.cicd.company.com