uberrebu
uberrebu

Reputation: 4329

gitlab-ci rules for manual job only on merge requests

I am finding it difficult to restrict a stage to only run on MR and be manual

I have the following rules

    rules:
        - when: manual
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
        - if: '$CI_COMMIT_BRANCH'
          when: never

but this stage is still running under branches, i do not want it to run on any branch, only on MR

it is literally driving me crazy. Code shows what should happen but it just does not follow it

So what am I missing?

Upvotes: 4

Views: 5172

Answers (1)

SomoKRoceS
SomoKRoceS

Reputation: 3043

From the documentation:

The job is added to the pipeline:

  • If an if, changes, or exists rule matches and also has when: on_success (default), when: delayed, or when: always.
  • If a rule is reached that is only when: on_success, when: delayed, or when: always.

The job is not added to the pipeline:

  • If no rules match.
  • If a rule matches and has when: never.

So in order to achieve your requirements (which are add manual job only on MR, otherwise, do not add the job) the right order should be:

rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: manual
    - when: never

This translate to: "When the first if matches -> add job manually, in all other cases -> don't add the job".

Upvotes: 5

Related Questions