In gitlab, how to set "pipelines must succeed" only for specific branches but not others for a merge request to merge?

Viewed 1832

In the merge checks settings, I have enabled the "pipelines must succeed" option:

enter image description here

But the branches without any jobs are stuck at merge by saying "waiting for pipelines status" and you can't merge without a successful pipeline.

Can I enable the "pipelines must succeed" option only for some specific branches like master/production?

2 Answers

As a workaround, you can trigger a merge request pipeline from the branches that don't currently have any jobs. The pipeline can have a single job that always passes. A merge request pipeline will only be created after a MR is created, not before.

A simple job like this should work:

print-info:
  stage: setup
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
  script:
    - 'echo "Job start: $CI_JOB_STARTED_AT"'
    - 'echo "Branch: $CI_COMMIT_BRANCH"'
    - 'echo "Commit Author: $CI_COMMIT_AUTHOR"'

Note: I'm not sure what your current pipeline looks like, so you may have to change the rules section to suit your needs.

Related