Trigger job upon pull request merg into master.

76 views
Skip to first unread message

Isaac Eliassi

unread,
Jan 22, 2017, 11:46:36 AM1/22/17
to Jenkins Users

Hi,

 

We are looking for a way to trigger a job when a pull request is being merged into master.

We would like to ignore all the other events, particularly pushing code directly to master.

 

We tried to configure the job as follows:

  1. Source Code Management
    1. Refspec (under advance)

+refs/pull/*:refs/remotes/origin/pr/*

    1. Branch Specifier

refs/heads/master

  1. Build Triggers

GitHub hook trigger for GITScm polling

 

The configuration above triggers the job for any merge to master.

 

Is there anybody that knows how to configure a job in such a way?

 

GitHub plugin - 1.25.1

Git plugin – 3.0.1

Git client plugin – 2.2.1

Jenkins ver. 2.32.1

Mark Waite

unread,
Jan 22, 2017, 11:54:55 AM1/22/17
to Jenkins Users
Interesting use case.

If you're using a pipeline job, and don't mind that the job starts only to end very quickly, then you could configure the Jenkinsfile to read the HEAD git commit and determine how many parents it has.  If it has more than 1 parent, then it is a merge commit and should be built.  If it has only one parent, then it should not be built, so you would exit quickly (and successfully) from the job.

You can probably configure your build scripts to do the same thing, depending on the build scripting system you use.

If you don't mind writing some code, the git plugin has a concept called a "build chooser".  The plugin implements a few build choosers, and the Git Chooser Alternative plugin implements more.  You could use the source code of the Git Chooser Alternative Plugin as a possible starting point for the type of chooser you're envisioning.

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fcaaee97-6d67-41ab-97bb-70bba73003b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Indra Gunawan (ingunawa)

unread,
Jan 23, 2017, 11:20:58 AM1/23/17
to jenkins...@googlegroups.com

Github does not differentiate between a merge or a push.  You should disallow direct push to master by making master a protected branch.

This way only Pull Request is allowed to be merged to master.

--

Isaac Eliassi

unread,
Jan 23, 2017, 4:46:40 PM1/23/17
to Jenkins Users
Hi,

Thanks for the advice, I am not using pipeline, but I will try to wrapper job and implement your idea.
I will post here a reply whether it worked. 

Isaac Eliassi

unread,
Jan 23, 2017, 4:48:52 PM1/23/17
to Jenkins Users, ingu...@cisco.com
Hi,

I can't make master a protected branch, since I am promoting the version as part of the triggered job.
Thanks for the idea anyway. 
Reply all
Reply to author
Forward
0 new messages