Search code examples
gitlabcontinuous-integrationgitlab-cigitlab-ci-runner

GitLab Merge Request falsely only shows/uses the jobs run throught `rules` as merge permission


I have changed a few jobs in our GitLab CI pipeline to only run under certain conditions, like this:

foo:
  stage: a
  rules:
    - exists:
        - "some/file"
    - changes:
        - "some/bla"
  script:
    - "echo 1"

All other jobs are implemented "normal", i.e., like this:

bar:
  stage: a
  script:
    - "echo 2"

We have setup the repository like that, that Merge Requests are only allowed to be merged if the pipeline succeeds. However, since this change, only the jobs that are listed through rules are applied to that, i.e., it looks now like this in the web interface:

Merge permission ok

and the UI would let me merge this, altough the latest "normal" jobs did not succeed at all:

all jobs

How can I enforce that all jobs need to succeed to mark a branch mergeable?


Solution

  • The solution to run only on branch OR merge request is to use (on GitLab 13.8 or later)

    workflow:
      rules:
        - if: $CI_PIPELINE_SOURCE == "merge_request_event"
        - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
          when: never
        - if: $CI_COMMIT_BRANCH
    

    Reference: Switch between branch pipelines and merge request pipelines