Hot to run Jenkins BUILD only if GIT commit's COMMENT value "equals to..."

1,066 views
Skip to first unread message

Elad Talby

unread,
Jul 22, 2014, 7:17:37 AM7/22/14
to jenkins...@googlegroups.com
Hello everyone,

I've setup an Android-Gradle job on Jenkins, that is triggered by a webhook on GitHub. 
Now, I'd like to have the Jenkins run the build only for 'release' commits and not every update. So decided to condition this by searching the commit's COMMENT for a specific value/string ("release version" for example).

I've searched the web but didn't find similar case.. only a git command that might help reading the comment itself:
git log --oneline -1
(where 1 refers to the first line - the comment field/line of the commit)
Thought maybe I can search for the 'release' trigger/string in the output of this command and CONDITION the execution of the build accordingly.

My question is: 
Assuming this whole request is applicable (Jenkins checking commit's comments field)-  How do I implement this condition in the build configuration on Jenkins? Should I use execute shell?
If there's a better way to do this - I'd be happy to hear :)


Many thanks!

-Elad

Mark Waite

unread,
Jul 22, 2014, 8:45:44 AM7/22/14
to jenkins...@googlegroups.com
If you're willing to consider a slightly different approach, you could decide that you'll modify only certain files for release (like a version number file, or a file named "release"), and then use the git plugin's "Additional Behaviour" section to add "Polling ignores commits in certain paths", then add that file into the inclusion list.

If you choose that technique, you'll need to also enable the "Force polling using workspace", since inclusion / exclusion processing needs a workspace.

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.
For more options, visit https://groups.google.com/d/optout.



--
Thanks!
Mark Waite

Elad Talby

unread,
Jul 22, 2014, 9:31:51 AM7/22/14
to jenkins...@googlegroups.com
Hi Mark,
thanks for the quick reply!

I will see if this form of conditioning can fit our needs and reply here with the results..
If you or anyone come up with other solutions for this matter - please post it here :)

Thanks!
-Elad

Björn Pedersen

unread,
Jul 22, 2014, 11:18:35 AM7/22/14
to jenkins...@googlegroups.com

Another idea would be not to trigger your job directly , but use a small intermediate job that checks the log first and then triggers your job only if the message suits.
Conditional Buildstep plugin or promoted buils come to mind here.

Björn

Elad Talby

unread,
Jul 22, 2014, 11:25:25 AM7/22/14
to jenkins...@googlegroups.com
Hello Bjorn,

Should it be simpler for the intermediate job to check this?   Can't I implement the same validation/check method in the main job?  

Thanks,
Elad.

Elad Talby

unread,
Jul 27, 2014, 1:53:36 PM7/27/14
to jenkins...@googlegroups.com
Hi,

Eventually got it working by using the 'file' trigger as you described (git plugin's "Additional Behaviour" > "Polling ignores commits in certain paths"... and included one file to be the trigger).
Thanks again for the advice here.

-Elad



On Tuesday, July 22, 2014 3:45:44 PM UTC+3, Mark Waite wrote:
Reply all
Reply to author
Forward
0 new messages