3

I can run a job for a merge request like so:

test:
  stage: test
  script: ./test
  only:
  - merge_requests

However, I also only want to run this job if the target branch is a specific one (e.g. master). Is it possible to do this?

Chin
  • 19,717
  • 37
  • 107
  • 164
  • check this out https://stackoverflow.com/questions/52746338/in-gitlab-ci-is-there-a-variable-for-a-merge-requests-target-branch – Tabare Apr 16 '19 at 18:07

2 Answers2

3

Merge request where the target branch is master:

only:
    refs:
        - merge_requests
    variables:
        - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
Oat Anirut
  • 1,179
  • 1
  • 8
  • 9
0

It is possible only starting from Gitlab 11.6 according to the docs https://docs.gitlab.com/ee/ci/merge_request_pipelines/

Anna Slastnikova
  • 1,260
  • 9
  • 9
  • 1
    Which part of that answer my question? It's just about the `merge_requests` pipeline option in general which I already had working – Chin Apr 17 '19 at 14:55