I want to run job only when there is merge request to specific branch. I configure .gitlab-ci.yml file as follow
stages:
- test
- deploy
test:
stage: test
only:
- develop
- merge_requests
deploy:
stage: deploy
only:
- master
- merge_requests
This will even run job deploy when merge request is for develop branch. How can I configure gitlab-ci.yml file so that when there is merge request for develop, test job will run and when there is merge request for master, deploy job will run.
You can use rules
for this case, by making gitlab-ci execute the job when there is a merge request targeting a specific branch like below
stages:
- test
- deploy
test:
stage: test
rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
when: always
deploy:
stage: deploy
rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
when: always
For more information check out the docs
try changing merge_request to merge_requests. The docs suggest using merge_requests, so I feel a typo is what is causing this issue for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.