1

Until now we were using Jenkins to run our build on any feature branch based on the Jenkins CI service. We are currently experimenting with pipelines based on gitlab-ci.yml. As a starting point I would like to limit this only for specific branches that created by few developers as a beta test.

I was trying to avoid merge of .gitlab-ci.yml from feature branches to release branches based on .gitattributes and merge strategies (see here), but this force me to have .gitlab-ci.yml in the release branch. As result gitlab force me to have some valid yml content (I hoped I could at least keep it empty) otherwise I will get invalid yml failure.

Any suggestion on keeping the .gitlab-ci.yml only on feature branch and avoiding manual steps to avoid the merge of .gitlab-ci.yml file until we will adopt it for all branches?

Similar questions:
https://forum.gitlab.com/t/how-to-ignore-gitlab-ci-yml-file-when-merging-the-branches/17948
GitLab merge behavior - keep file from branch

Community
  • 1
  • 1
Haim Raman
  • 11,508
  • 6
  • 44
  • 70
  • You could just merge it but excluding the release branches by using `except: - branch-name` – Bertrand Martel Jun 10 '20 at 17:05
  • This is a simple solution that may work, following your lead I was reading on rules https://docs.gitlab.com/ee/ci/yaml/#rules (I am using version 12.3) maybe this will be better – Haim Raman Jun 11 '20 at 05:31

2 Answers2

0

Following Bertrand response and as I don't actually care to have the .gitlab-ci.yml in release branches as long as the pipelines execute only on selected merge requests. I changed my .gitlab-ci.yml to include a rule. According to the logic below the pipeline will be executed only on merge request with the branch name format FTR-ddddd-g

image: maven-mta:latest
variables:
  GIT_DEPTH: 0
Unit tests and Sonar Check:
 script:
    - mvn clean verify sonar:sonar
  artifacts:
    reports:
      junit:
        - "*/target/surefire-reports/TEST-*.xml"
  allow_failure: false
  rules:
    - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^FTR-\d+-gl/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
      when: always
  tags:
  - sonarqube
  - docker

I got an unexpected side effect (which I actually like) on the merge requests meeting the criteria above the Jenkins CI Service is not running. Unfortunately I didn't found any documentation supporting this behaviour and the following page recommend to disable Jenkins CI when having gitlab ci.

Haim Raman
  • 11,508
  • 6
  • 44
  • 70
0

"As a starting point I would like to limit this only for specific branches"

you can use the only tag.

  only:
    - feature-*
Nitesh chauhan
  • 316
  • 2
  • 5