3

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?

uberrebu
  • 3,597
  • 9
  • 38
  • 73

1 Answers1

5

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".

SomoKRoceS
  • 2,934
  • 2
  • 19
  • 30
  • 1
    yeah i later figured i needed to move `when: manual` under the first rule..so yup this is answer...thanks for it anyways – uberrebu Dec 04 '21 at 00:19