Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - Dont build for specific commiter or commit message

I'm having some issues with Jenkins and its Git plugin.

Currently, a Gitlab server is triggering the builds but I want to configure the job so that it doesn't build when a specific message is included in the commit.

I've tried using the ci-skip plugin (https://github.com/banyan/jenkins-ci-skip-plugin) but instead of not starting the job, the plugin allows it to start but then aborts it.

It does the job but I'm having aborted builds in Jenkins history and I'm trying to avoid that.

Anyone managed to do that?

like image 914
Nick Tsitlakidis Avatar asked Nov 29 '15 10:11

Nick Tsitlakidis


People also ask

What happens if you dont specify a commit message?

Committing in Git without a message So if you don't have anything to commit, you will be told that there is nothing to commit without the text editor being opened. So if your text editor opens up after the command, there is definitely something to commit.

How do I build on specific commit in git on Jenkins?

Pass the commit sha1 to a predefined parameter and in Build-Execute shell run git checkout <commit> before the build process starts. Some extra work is needed to make sure the check-out goes well. Check the box This project is parameterized and then you can add predefined parameters.

How do I skip a build in Jenkins?

use the "Set the build result" step to set the status to "Aborted", this will finish the Jenkins build and will hide the build from the Jenkins dashboard.


2 Answers

Jenkins git plugin itself already provides these kinds of advanced usage.

Exclude specific messages

Job config page -->Source Code Management-->Git-->Add -->Polling ignores commits with certain messages

Exclude specific commiters

Job config page -->Source Code Management-->Git-->Add -->Polling ignores commits from certain users

Don't forget to click the help at the end of each of them to learn the correct way of usage.

like image 77
mainframer Avatar answered Oct 16 '22 18:10

mainframer


If you have not yet found a solution:

  1. Configure your job to poll SCM but do not enter a timeplan for that (ignoring the warning that your job would never run.

  2. Configure the scm section to ignore commits, users, etc.

  3. Use a trigger for your jobs as follows: http://yourserver/git/notifyCommit?url=<URL of the Git repository>[&branches=branch1[,branch2]*][&sha1=<commit ID>] as seen on Git Plugin page

Whenever the URL is called, jenkins will scan for jobs that are using this repository. Then it checks for any specific settings (e. g. ignoring commits by certain users or with some commit messages) and either run the build or not. Of course the build will always somehow start to poll scm and check for commits, but if it is cancelled due to unimportant commits you will not see an aborted build in your history.

like image 33
Clerenz Avatar answered Oct 16 '22 17:10

Clerenz