-1

I have the following the .gitlab-ci.yml:

stages:
  - build

workflow:
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
      variables:
        ENVIRONMENT_TYPE: 'prod'
    - if: $CI_COMMIT_REF_PROTECTED == 'true' && $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
      variables:
        ENVIRONMENT_TYPE: 'preprod'
    - if: $CI_COMMIT_REF_PROTECTED == 'false'
      variables:
        ENVIRONMENT_TYPE: 'review'
    - if: $CI_MERGE_REQUEST_ID
      when: never
Compile:
  stage: build
  image: node
  only:
    - branches
  script:
    - yarn install
    - yarn build

and if my branch is feature/xyz, and I push, it runs the pipeline which is wanted. but if I merge, the pipeline won't run on master branch.

I added:

    - if: $CI_MERGE_REQUEST_ID
      when: never

Because if I push to my normal branch, it will run 2 pipelines rather one (a detached pipeline is introduced).

Can someone pelase help what am I missing?

Dom
  • 580
  • 4
  • 26
  • Just looking at https://docs.gitlab.com/ee/ci/yaml/, where's your `- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH`? (which is in the docs when you search for `merge` with a helpful comment "Run this job when commits are pushed or merged to the default branch") – Mike 'Pomax' Kamermans Sep 24 '21 at 21:10
  • @Mike'Pomax'Kamermans, not sure where in the docs it states that `if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH` means that I'm searching for `merge` with a helpful comment "Run this job when commits are pushed or merged to the default branch" if I understood you correctly. However, this is not correct and that statement is not the issue. However that if condition means `Run this job when commits are pushed or merged to the default branch` (search for it in the same link) – Dom Sep 25 '21 at 17:00

1 Answers1

0

After more investigations, it turns out that there was nothing wrong with the .gitlab-ci.yml I posted in the question.

It was all perfect.

It turns out that I had AUTO_STOP: 0 environment variable in one of the workflows which was preventing the pipeline from running. (undocumented variable https://docs.gitlab.com/search/?query=AUTO_STOP )

I was able to reproduce this, and I reported this as an issue https://gitlab.com/gitlab-org/gitlab/-/issues/341713. Here is the reproduced merge https://gitlab.com/adham.sabry/pipeline-test/-/merge_requests/5 where the protected branch did not have pipeline to start.

I hope this helps and no one stumbles across this.

Dom
  • 580
  • 4
  • 26