I have 2 jobs as part of my pipeline and would like to trigger them as below
- Job-1, on every push to merge request
- Job-2, Once review is completed and merge request is ready to merge, would like to trigger Job-2. Based on Job-2 status (success/fail) merge branch should merge to main. I tried to trigger Job-2 on pressing ‘merge’ button in merge request but could not find way to trigger it.
Is there any other way to achieve this?
Hi! You can accomplish the first job functionality with standard gitlab features. For the second job, you are looking for merge trains. This is a ee feature.
the first part is default behavior of merge request pipelines.
the second part is not possible out of the box as you describe it, GitLab is built around verifying the changes in pipeline after each commit/push unless you limit the job by set of
You could define a rule for a job to run only after MR is approved using
CI_MERGE_REQUEST_APPROVED variable. But someone would still need to push a change to a Merge request AFTER it’s approved to start a pipeline.
merge trains won’t help you. That’s about running pipelines on multiple MRs sequentially.
You can have a different set of Jobs to run on Branch and different set of Jobs to run on Merge request. So for example, developer can do change to a feature branch, push changes and run CI jobs before raising a Merge request. Branch pipeline would have your Job-1. Merge request pipeline would have your Job-2.
Thanks for the response. Yes, I’m able to configure first part.
For second part, currently I configured to run the job based on “merge_request_event” and
CI_MERGE_REQUEST_APPROVED variable set to ‘true’. However, as you rightly pointed out, someone still needs to push to trigger the pipeline as approving merge request is not an event. I’m looking to avoid that extra push at end to trigger this pipeline.
Is it possible to use webhooks/gitlab api to trigger pipeline based on “merge” or “approve” button?
I am not aware of any trigger based on
merge button will trigger branch pipeline on target branch.