Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Jenkins build every 2 hours but only if there was a git commit

Tags:

git

jenkins

Here is the problem that I am having - I need to trigger a job build every 2 hours but only if there was a git commit(skip if there was no activity). I can solve them individually but not sure how to solve them together - anybody has any good ideas? The only one I can come up with is a cron job that would check every 2 hours and if there is a git commit during that time, trigger a job manually, but that does not look all that elegant.

Any good ideas appreciated.

like image 811
Sergey Avatar asked Jul 09 '14 18:07

Sergey


People also ask

Can Jenkins build be triggered automatically?

Follow the steps as mentioned below to trigger a Jenkins job automatically based on GitHub's webhook configurations: Step 1: Go to the Configuration page of the respective job and under the build trigger section, check the "GitHub hook trigger for GITScm polling" checkbox and click on the Save button.

Is it possible for SCM to check whether changes were made ie new commits and builds the project if new commits were pushed on Jenkins?

You can trigger build by following two methods: Poll SCM : periodically polls the SCM to check whether changes were made (i.e. new commits) and builds the project if new commits where pushed since the last build. build periodically : builds the project periodically even if nothing has changed.


2 Answers

Set jenkins up to use the "Poll SCM" trigger every 2 hours (0 */2 * * *) or something like that

It'll update from git and, if there was a change, trigger a build.

like image 168
Angelo Genovese Avatar answered Oct 12 '22 02:10

Angelo Genovese


H H/2 * * *

Poll SCM will occur at random minute every random intervals of 2 hrs.

like image 41
abhinav Avatar answered Oct 12 '22 01:10

abhinav