jenkinsci / gitlab-branch-source-plugin

A Jenkins Plugin for GitLab Multibranch Pipeline jobs and Folder Organization
https://plugins.jenkins.io/gitlab-branch-source
MIT License
124 stars 94 forks source link

Am I forced to build all branches when pushing to the target branch of multiples MRs ? #140

Open fmarot opened 3 years ago

fmarot commented 3 years ago

Hello, sorry to post as an "issue" but I found no other way to ask my 2 questions :/ The title of this issue regards the second question.

1- I have a multibranch Pipeline job in Jenkins previously set up only with the "git" plugin. With this "Gitlab Branch Source plugin" Jenkins now detects MergeRequests as MR and build them specifically. But I still have to keep the classic git plugin otherwise my job is not notified when new commits are pushed. I this the intended behavior ? I was expecting to need only the "Gitlab Branch Source plugin", not both plugins at the same time.

2- From what I experienced with "Gitlab Branch Source plugin", a push in a branch set as target of multiple MRs will trigger a build of all those MR at the same time. It is a problem for my job because my legacy application takes a long time to build and I do not want this behavior: I would like the MR job to build only when there is a push in the corresponding source branch of the MR. Or build it when I decide. Not upon any commit in the MR's target branch. Is it possible ?

Regards (and again sorry to post here, I found no other support channel)

Adityanr commented 3 years ago

To answer your second question, set Discover merge requests from origin as The current merge request revision : merge_request_gitlab_jenkins

This will ensure that only merge request source branch pipelines will be built.

fmarot commented 3 years ago

Thanks @Adityanr . In fact I've just tested the setting you propose and while it has the effect of not building other MR targetting a branch when this branch changes, it also has the effect of building not the virtual result of the merge of the source branch in the target branch, but only builds the source branch of the MR. Thanks I think I will use this setting, but I'm wondering why changing this setting changes 2 behaviors at the same time...

To sum up:

setting "The current merge request revision":

"merging the target branch with the current merge request revision":

Adityanr commented 3 years ago

Now that's the problem I'm trying to tackle myself...that it builds all merge requests pointing to a target branch upon any commit to that target branch on this setting: "merging the target branch with the current merge request revision":

The reason behind this i believe is that:

Merge request pipeline builds only upon a push by developers. Say you want the merge request pipeline to run a build in a situation where the source and target branches are merged ("merging the target branch with the current merge request revision"). This is only possible if we consider merging of the latest commit to source branch and latest commit to target branch. For that to happen, the pipeline must also be built when target branch has new commits, to demonstrate the exact behavior, when source and target branches of merge request are merged. I have raised an issue myself as a proposed solution to tackle the issue to an extent:

https://github.com/jenkinsci/gitlab-branch-source-plugin/issues/137

This will prevent the MR source branch from being too far behind the target branch. At the same time preventing a bazillion pipelines from running. Not an answer to a question but a possible improvement.

markjacksonfishing commented 3 years ago

Thank you for this issue. Also noting our twitter convo

jakubriegel commented 2 years ago

Hi! I think my question fits this discussion. My desired behavior is to have all MRs rebuilt when target branch is updated. It doesn't work for me, regardless which setting I use. But when I manually run project scanning, it triggers builds for MRs without new changes but targeting to changed branch. May I have something configured wrongly? Do I need system web hooks for this feature? @markyjackson-taulia

austen-herbst commented 2 years ago

Hi! I think my question fits this discussion. My desired behavior is to have all MRs rebuilt when target branch is updated. It doesn't work for me, regardless which setting I use. But when I manually run project scanning, it triggers builds for MRs without new changes but targeting to changed branch. May I have something configured wrongly? Do I need system web hooks for this feature? @markyjackson-taulia

@jakubriegel Were you able to get this working? I am facing the exact same issue. I can only get all MRs rebuilt when I manually scan the project.

jakubriegel commented 2 years ago

@austen-herbst Hi! I've found two good enough solutions:

As we already have some logic for handling GitLab events, I went with the second option.

But I does not fix the issue 🙃

austen-herbst commented 2 years ago

@jakubriegel Thanks for the ideas!

I hadn't thought of the second idea. I just tried it out and it works quite well with this plugin. Thanks again!