1 minute read
On this page

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.

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
    - main
    if: cloudbees.scm.repository == ''
    - uses: cloudbees-io/checkout@v1
    - uses: cloudbees-io/kaniko@v1
        destination: my.registry/my-image