Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow merge requests to trigger multibranch builds. #857

Closed
wants to merge 1 commit into from

Conversation

omehegan
Copy link
Member

@omehegan omehegan commented Nov 23, 2018

Fixes #416.

The plugin's original implementation of Pipeline Multibranch job triggering only supported triggering from GitLab push webhooks. My understanding is that this was because, in the case of Multibranch jobs, the plugin just triggers branch indexing and lets Jenkins trigger the builds themselves for whichever branches have changes. As a result, there is no way to pass any of the data from the GitLab webhook to a Multibranch job, and so when building from an MR the job would not have any of the data about source and target branch which could be used for performing a local merge and so on.

However, enough people have complained about the fact that you cannot even trigger a Multibranch build from a Merge Request that I have tried to remedy that. A better long-term solution would be to add Jenkins SCM Branch Source support to the plugin, and refactor the way Multibranch jobs are triggered in the process.

@omehegan omehegan changed the title Allow merge reqeusts to trigger multibranch builds. Allow merge requests to trigger multibranch builds. Nov 23, 2018
@omehegan
Copy link
Member Author

@pdudits if you have some time, could you review this? I was just feeling my way along a bit blindly here :)

@pdudits
Copy link
Contributor

pdudits commented Nov 23, 2018

Without a test case it's surely hard to tell the effect. Since this is entirely new branch of code, it might be safe to integrate. I have some proposal to cleaning that up, though, I'll post a review.

@omehegan
Copy link
Member Author

@pdudits thanks very much!

private final static Logger LOGGER = Logger.getLogger(PushBuildAction.class.getName());
private final Item project;

public SCMSourceOwnerNotifier(Item project) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class only makes sense when given an SCMSourceOwner. At the call site this is already verified, so it's nicer to just allow these as projects

Suggested change
public SCMSourceOwnerNotifier(Item project) {
public SCMSourceOwnerNotifier(SCMSourceOwner project) {

}

public void run() {
for (SCMSource scmSource : ((SCMSourceOwner) project).getSCMSources()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can remove any casts to SCMSourceOwner in the method

if (scmSource instanceof GitSCMSource) {
GitSCMSource gitSCMSource = (GitSCMSource) scmSource;
try {
if (new URIish(gitSCMSource.getRemote()).equals(new URIish(gitSCMSource.getRemote()))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this as if (a.equals(a)). Both the constructor and getRemote() return the same thing. So the try block, and the if block can be removed.

@erenatas
Copy link

Are there any specific reasons to why this MR is not being accepted?

@carloscaverobarca
Copy link

+1 to accept this MR, currently I am using two separate job, one multibranch (created using DSL) and one normal pipeline for the MR, so the ideal solution for me would be to cover MR with the multibranch plugin.

@erenatas
Copy link

+1 to accept this MR, currently I am using two separate job, one multibranch (created using DSL) and one normal pipeline for the MR, so the ideal solution for me would be to cover MR with the multibranch plugin.

This will in the end create an unnecessary work... If it won't get merged that's what I will have to do also..
@carloscaverobarca if you have spare time, can you tell me how did you set a normal pipeline for merge requests? I have been trying to do it but builds does not trigger from gitlab. Push trigger starts the pipeline but merge request trigger does literally nothing. I would be very glad if you could help.

@carloscaverobarca
Copy link

carloscaverobarca commented Mar 14, 2019

Sure. We used Gitflow workflow with develop and master branches. I defined a normal pipeline job with this configuration (same gitlab repository) including MR to master (see configuration in the second snapshot):

build-configuration

Pipeline

You also need to add a new MR webhook in GitLab to the jenkins job

webhooks

I realized just now, that it is possible to modify the jenkins jobs multibranch pipeline is generating, so probably it is not needed to add a new job, just only modify the one you need to Pipeline script from SCM:

pipeline-configuration

@erenatas
Copy link

@carloscaverobarca Thank you so much for the reply! Unfortunately I don't have that option in a normal Pipeline job. I wonder if you have installed a plugin to get that option. I use Jenkins from stable image inside Docker. Maybe I should use latest?

@carloscaverobarca
Copy link

carloscaverobarca commented Mar 15, 2019

@erenatas, I guess you need to install also the pipeline plugins, my installation is this one:
Jenkins 2.1.60
Gitlab plugin 1.5.11
Pipeline set of plugins:

imagen

Hope it helps!

@erenatas
Copy link

@carloscaverobarca you are the best! Thank you so much. I will try and let you know when I'm back at my laptop. Cheers!

@erenatas
Copy link

@pdudits Are there any possibilities for reviewing and accepting this soon? Otherwise I will work on a workaround. Thanks!

@pdudits
Copy link
Contributor

pdudits commented Mar 15, 2019

@erenatas I am not the member if the repo, just helping out with the code reviews. So merging fully depends on time @omehegan is able to allocate for this.

What I can suggest though is:

@carloscaverobarca
Copy link

@erenatas glad to help! @pdudits I will try to check whether it works and help @omehegan if I have time next week, the plugin is quite useful and cool.

@carloscaverobarca
Copy link

@erenatas BTW found this interesting blog to install the plugins you need (even adapt your git repo) to generate your Jenkins developer docker image

@erenatas
Copy link

erenatas commented Apr 5, 2019

@erenatas BTW found this interesting blog to install the plugins you need (even adapt your git repo) to generate your Jenkins developer docker image

I haven't had the time to try the plugin yet due to the exams of my master's degree. Instead of doing it like this, I thought of getting backups of jenkins_home. I created a jenkins volume and get tar of volume.

I need to build this plugin and try it on Monday. I will definitely let you know.

@MikeSafonov
Copy link

MikeSafonov commented May 22, 2019

Any plans to merge this PR?

@erenatas
Copy link

Sorry I have forgotten to reply to this ticket. I couldn't make it work unfortunately.

@carloscaverobarca
Copy link

carloscaverobarca commented Dec 13, 2019

I could not make it work. I installed the version and Merge Requests are not launched. Currently I have no time to help with the source code. For the moment I am using the multibranch job and another pipeline job for the Merge Requests.

@MarkEWaite MarkEWaite closed this May 6, 2023
@MarkEWaite MarkEWaite deleted the multibranch-mr-support branch May 6, 2023 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge request hooks are ignored for multibranch jobs
6 participants