gitlab-branch-source-plugin icon indicating copy to clipboard operation
gitlab-branch-source-plugin copied to clipboard

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

Open fmarot opened this issue 4 years ago • 8 comments

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)

fmarot avatar Apr 26 '21 07:04 fmarot

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.

Adityanr avatar Apr 26 '21 12:04 Adityanr

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":

  • builds the content of the source branch as-is
  • builds only this branch

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

  • builds the local result of the merge of MR's source into MR's target
  • builds all MR targetting a branch when this branch changes

fmarot avatar Apr 26 '21 13:04 fmarot

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.

Adityanr avatar Apr 26 '21 20:04 Adityanr

Thank you for this issue. Also noting our twitter convo

markjacksonfishing avatar May 10 '21 18:05 markjacksonfishing

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 avatar Dec 23 '21 08:12 jakubriegel

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.

austen-herbst avatar Jan 25 '22 22:01 austen-herbst

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

  • in job config you can set up rescan to be triggered automatically on fixed interval,
  • you can listen to merge events from GitLab and maunally trigger rescan after merge.

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

But I does not fix the issue 🙃

jakubriegel avatar Jan 28 '22 14:01 jakubriegel

@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!

austen-herbst avatar Jan 28 '22 23:01 austen-herbst