I have a .gitlab-ci.yml that looks like this:
before_script:
- omitted
deploy_production:
script:
- omitted
only:
- master
deploy_staging:
script:
- omitted
only:
- development
My expectation is that my pipelines will run only for 2 selected branches. But Gitlab runs them for all the commits to any branches:
Each pipeline is failed due to no jobs:
How can I disable running pipelines for all branches and leave just selected?
Hi I did in this way:
stages:
- build
#BUILD DEVELOPMENT
build_development:
image: docker:stable
rules:
- if: $CI_COMMIT_REF_NAME == "development" #when commit pushed in this branch it will trigger this job
stage: build
script:
- echo "Hello world"
#BUILD MAIN
build_main:
image: docker:stable
rules:
- if: $CI_COMMIT_REF_NAME == "main" #when commit pushed in this branch it will trigger this job
stage: build
script:
- echo "Hello world"
Dont use onyl that is deprecated, with rules you can specified in more details which branch and other stuff. In this way I made different job for different branches, you can also specify the feature/* branches but I didnt try it yet. Let me know
1 Like