GitLab CI Pipeline on specific branch only
Solution 1
It was my mistake - I had two different .gitlab-ci.yml files in develop
branch and feature/some-feature
branch and that's why the Pipeline was executed for all branches.
Solution 2
Although it has been passed much time on this discussion I would like to suggest an opinion, which I am using most of the time.
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "master"'
when: on_success
changes:
- folder/some_folder/**/*
- if: '$CI_PIPELINE_SOURCE == "web" && $CI_COMMIT_BRANCH == "development"'
when: manual
changes:
- folder/some_other_folder/**/*
This structure solved my various problems, I hope it helps you to!
Regards.
ProximaCygni
Updated on July 25, 2022Comments
-
ProximaCygni almost 2 years
I'm trying to implement GitLab CI Pipelines to build and deploy an Angular app. In our project we have two general branches:
master
(for production only) anddevelop
. For development we createfeature/some-feature
branches fromdevelop
branch. When development finished, we create merge request fromfeature/some-feature
todevelop
. When merge request approved and merged intodevelop
branch I want to run a Pipeline in order to build application and deploy the build on some environment.I use the following setup in .gitlab-ci.yml:
image: node:7.5-configured stages: - build - deploy build_job: stage: build only: - develop script: - /bin/bash <some script here> ...
The problem is that Pipeline executed every time I push into any
feature/some-feature
branch. What's wrong with my setup? How can I force the Pipeline to be executed only when push performed intodevelop
branch directly?Solution It was my mistake - I had two different .gitlab-ci.yml files in
develop
branch andfeature/some-feature
branch. -
LostPhysx about 3 yearsBut then I need to add it to .gitignore as well, right? Otherwise it will overwrite the .gitlab-ci.yml in the master branch when I merge.
-
user3389196 over 2 yearsThis doesn't solve the problem. The .gitlab-ci-yml file will eventually end up on other branches because they're creating new branches from development and merging into development. I'm not sure about the .gitignore comment but that file isn't really meant for this.
-
Shapeshifter almost 2 yearsIt may help for the reader's if you explained why this is a better alternative. It would be appreciated