jobs.<job_id>.if

1 minute read

Use jobs.<job_id>.if to skip a job, not to force running it if an upstream job failed. You can use any supported context and expression to create a conditional.

When you use expressions in an if conditional, you may omit the ${{ }} expression syntax because CloudBees automatically evaluates the if conditional as an expression. However, this rule does not apply everywhere.

You must use the ${{ }} expression syntax or escape with '', "", or () when the expression starts with !, since ! is reserved notation in YAML format.

Using the ${{ }} expression syntax turns the contents into a string, and strings are truthy. For example, if: true && ${{ false }} evaluates to true.

CloudBees strongly recommends that you avoid mixing use of the ${{ }} expression with other logic, as you may get unexpected results.

Contexts

Conditionals can be at both the job and step level. A conditional within a job cannot reference any step outputs, because some steps have not yet run.

Example usage

In the following example, a conditional determines when the production-deploy job can run. It will only run if the repository is named bee-repo-prod and is within the bee-org organization. Otherwise, the job is marked as skipped.

name: example-workflow on: push: branches: - main jobs: production-deploy: if: cloudbees.scm.repository == 'https://scm.example.org/bee-org/bee-repo-prod' steps: - uses: cloudbees-io/checkout@v1 - uses: cloudbees-io/kaniko@v1 with: destination: my.registry/my-image