am2505
am2505

Reputation: 2384

Gitlab-ci.yml Configuration

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.

Upvotes: 1

Views: 389

Answers (2)

Mostafa Hussein
Mostafa Hussein

Reputation: 11940

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

Upvotes: 1

Abishek Aditya
Abishek Aditya

Reputation: 812

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.

gitlab ci docs

Upvotes: 0

Related Questions