Replace old syntax only - trigger with rules


In my gitlab-ci yamls I use:

  - triggers

I know that only is slowly becoming obsolete, although it can still be used, but I’d like to use rules for the new projects in any case.

So how could I replace this so using rules?

I’ve had a look at the documentation (Keyword reference for the `.gitlab-ci.yml` file | GitLab )and they can’t be used together in the same job. If you configure one job to use both keywords, the GitLab returns a key may not be used with rules error., but I’m not sure how I can do it.

  - if: triggers

maybe? :slight_smile:

Or maybe this?


Hi @lethargos

I think you want something like:

    - if: "$CI_PIPELINE_SOURCE == 'trigger'"
      when: on_success
    - when: never

The CI_PIPELINE_SOURCE variable is documented here.

1 Like

Thanks for the reply!
Can I ask what the difference between the two when directives is? I’m not sure I follow.

The first one only applies if the if statement above returns true.

The third line, - when: never is the default for this job. So if "$CI_PIPELINE_SOURCE == 'trigger'" returns false then when: never is applied.

Note the - in front of the second when which starts the next row in the YAML matrix.

1 Like