My preference for merging is fast forwarding/rebasing. So I would like to run each stage upon ever commit, to ensure issues are fixed in the commit they are introduced, rather than just checking the HEAD of the merge request.
I tried removing
rules:
- if: $CI_MERGE_REQUEST_ID
and within the pipelines section of the merge request I can see it being ran for each commit. However, if one fails I am still able to merge the request as the pipeline for the merge request passed.
How am I able to make a merge request unmergeable if a pipeline failed for a commit within a branch I am attempting to merge?
I am not sure I understand your problem, but you can go to settings -> general -> Merge requests -> Merge checks and check the box Pipelines must succeed .
So yes that setting will enforce the pipeline for the merge request to pass i.e. stages which include the rule below before it can be merged.
rules:
- if: $CI_MERGE_REQUEST_ID
But I have stages I want to pass for every commit within the branch before the merge request can be merged.
E.g. below is from a merge request I have open. I have two stages that run per merge request, both pass so the UI will let me merge it.
Yet I also have stages I run for every commit within the branch and if any of them fail I do not want the merge request to be mergable. So you will see I had test failures on the commits pipeline but because the merge request pipeline was fine it would let me merge.
Because a merge request only tests the HEAD of the branch. I want each commit in the branch to be tested, because I am fast forward merging every commit onto the main branch and I want each commit to be atomic and revertable.
Here is the link to the merge requests .gitlab-ci.yml not sure how it will help.
On the first push, in a feature branch, we create an MR. and on the next pushes to the MR, the entire pipeline is run against the commit. And if something is wrong we are not allowed to merge the MR.
Well that would just solve the first edge cases I listed not the others.
Anyways, I am looking for a more officially supported method of including the pipeline results for each commit in a branch’s merge request if anybody can help?