I want the Gitlab pipeline to be initiated only when there is a merge request. Not on commits to any branch.
only:
refs:
- merge_requests
changes:
- "**/*.json" except:
- $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == "master"
- $CI_COMMIT_REF_NAME == "master"
But when I create a merge request there are two pipeline request initiated. One for
- Detached merge request pipeline : this is initiated when the merge request is created (not yet approved). I want this pipeline run to be blocked. But this run has all MR variables populated.
FYI I have some rules to set variable values and read this is causing this issue. I tried the below as mentioned here:(https://gitlab.com/gitlab-org/gitlab/-/issues/201845) to block the Detached pipeline and it works. But now I have no way to access the MR variables.
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_OPEN_MERGE_REQUESTS
when: never
- Merged branch pipeline: this is initiated after the merge is completed/approved. I want only this pipeline to be initiated. But on this branch all the merge request variables - CI_MERGE_REQUEST_SOURCE_BRANCH_NAME and CI_MERGE_REQUEST_TARGET_BRANCH_NAME are all EMPTY.
How to achieve the following:
Block pipeline run for Detached branch request and get the MR variables for Merged branch pipeline run?
Update 1: I enabled merged result pipeline on settings and removed the MERGE_REQUEST_IID rule. Now the merge RESULT pipeline is running instead of Detached but the merged result pipeline is executing before the merge is approved? Sorry this is confusing. Is there anyway to initiate a pipeline ONLY after the merge is approved and get access to MR variables in that pipeline run?