Conditional Tasks

Allow tasks to only be run on certain git refs / branches

Within a pipeline, you sometimes want to run tasks only for specific branches. The "when:" property for tasks allow you to specify a regular expression. If the expression is met, only then will a task run as part of the pipeline. It is important to note that Sail CI uses the full git ref to match the regular expression.

Full information about different types of refs:
https://git-scm.com/book/en/v2/Git-Internals-Git-References

Simple Pipeline

If you are using a simple pipeline without workflows you can simply add the when property to each task to specify a regex of a ref. If the regex matches the task will run as part of your build.

tasks:
  deploy:
    image: sailci/example
    when: \/heads\/master$

Workflows

If you have opted into using a workflow you can also use the "when:" property on each task of a workflow instead of on a top level task as shown above.

tasks:
  deploy:
    image: sailci/example
workflow:
  - deploy:
    when: \/heads\/master$