Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Jenkins from polling SCM (Git) while build is running

Let's say I have a build which takes 5 minutes to run, and SCM polling is set to run every 2 minutes (H/2 * * * *). If a commit is pushed, Jenkins polls and finds changes and starts build #1. After 2 minutes have elapsed and build #1 is still running, Jenkins polls again, finding the same "change" (which is already being built), and it queues build #2.

I have "do not build concurrently" set for the project.

It appears that the "last built revision" is not updated until the build completes. You can imagine, if I queue up 5-10 different projects around the same time, then Jenkins will slow down (running simultaneous builds from different projects), and polling for each of those projects will continue to add another build for the same commit which is already queued or building.

How do I disable polling while the same project is building? (Changing polling to check every 5+ minutes instead is not the proper solution.)

TL;DR I don't want my Jenkins projects to poll while they are already building, or a build is queued.

like image 448
Josh M. Avatar asked Aug 03 '18 13:08

Josh M.


People also ask

What is the difference between build periodically and poll SCM in Jenkins?

1 Answer. "Poll SCM" polls the SCM periodically for checking if any changes/ new commits were made and shall build the project if any new commits were pushed since the last build, whereas the "build" shall build the project periodically irrespective to whether or not any changes were made.

What is poll SCM schedule in Jenkins?

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, whereas build periodically builds the project periodically even if nothing has changed.

What is polling in git?

Fast Remote Polling is a feature that uses a speedy 'git ls-remote ...' command to perform the SCM polling action rather than having to a clone and fetch a local repository. This feature is enabled by default as of versions 2.2+.


2 Answers

There is no fix for this issue other than switching to webhook-based builds, which is what we did, and never looked back.

like image 110
Josh M. Avatar answered Oct 19 '22 05:10

Josh M.


As of a few years ago the Jenkins project declined to add this feature:

https://issues.jenkins-ci.org/browse/JENKINS-8950 - disable polling if build is running.

like image 37
AaronDossett Avatar answered Oct 19 '22 05:10

AaronDossett