Jenkins Git SCM Polling stops when the job for which polling is happening is running - jenkins

We have a job in a jenkins environment which is triggered based on the changes found in the git source code repository.
When the job is running, the git polling log shows nothing and until the job finishes the execution, polling log doesn't have anything on it.
It always shows log after completing the job and another note is that, enable concurrent builds option is not set to make sure only one build runs at a time.
I would like to understand whether it is a known behavior on jenkins front to halt polling when the job is running and whether the concurrent builds option is enabled or not?

I had a similar problem and discovered this: https://issues.jenkins-ci.org/browse/JENKINS-7423
It looks like it's related to the polls requiring a workspace in order to perform the checkout. You can manually kick off new builds and they will pick up SCM changes.

Related

How to avoid scheduling/starting multiple runs of a Jenkins job at the same time

We are moving over our build system from Hudson to Jenkins and also to declarative pipelines in SCM. Alas, it looks like there are some hiccups. In Hudson, when a job was scheduled and waiting in the queue, no new jobs were scheduled for that project, which makes all the sense. In Jenkins, however, I observe there are e.g. 5 instances of a job started at the same time, triggered by various upstream or SCM change events. They have all even kind of started, one of them is actually running on the build node and the rest are waiting in "Waiting for next available executor on (build node)". When the build node becomes available, they all dutifully start running in turn and all dutifully run through, most of them without no purpose at all as there are no more changes, and this all takes a huge amount of time.
The declarative pipeline script in SCM starts with the node declaration:
pipeline {
agent {
label 'BuildWin6'
}
...
I guess the actual problem is that Jenkins starts to run these jobs even though the specified build node is busy. Maybe it thinks I might have changed the Jenkinsfile in the SCM and specified another build node to run the thing on? Anyway, how to avoid this? This is probably something obvious as googling does not reveal any similar complaints.
For the record, answering myself. It looks like the best solution is to define another trigger job which is triggered itself by SCM changes. It should do nothing else, only checks out the needed svn repos (with depthOption: 'empty' for space and speed). The job needs to be bound to run on the same agent than the main job.
The main job is triggered only by the first job, not by SCM changes. Now if the main job is building for an hour, and there are 10 svn commits during that time, Jenkins will schedule 10 trigger job builds to run. They are all waiting in the queue as the agent is busy. When the agent becomes available, they all run quickly through and trigger the main job. The main job is triggered only once, for that one must ensure its grace/quiet period is larger than the trigger job run time.

Gerrit Trigger doesn't work when a build is running for that gerrit

This is a weird one.
On Jenkins, with Gerrit Trigger, I can trigger my jenkins job just fine using any of the configured triggers.
However, while that job is running - I can not trigger the same job again from the same gerrit so long as the previous build is still running.
I can trigger the same job from other gerrits, or trigger other jobs from that gerrit, but not the same job and the same gerrit.
Funny thing is - it's not even queued. The trigger is just completely ignored, it doesn't even start when the running job is finished.
Thins I've checked are that Do not allow concurrent builds is not checked (it indeed isn't) and that the label has enough executors available (it does).
Any idea what I could be missing?
Thanks!

Jenkins not building after push, but Github webhook is working

I think I've done the hard part already: the Github webhook after a push always returns a success message.
I can build manually. But it never builds after the push, because "polling" never happens.
Both the GitHub Hook Log and Git Polling Log say "Polling has not yet run".
Here is my configuration:
Branches to build: refs/heads/checkJenkins
Build Triggers: GitHub hook trigger for GITScm polling, Poll SCM
Build: Execute shell: 'git pull'
Any ideas on how to get the polling started?
A side question: which should be doing the polling when I'm using the webhook in github: the "GITScm polling" or "Poll SCM"? Can I delete one of those settings?
Poll SCM is to scan the repository for changes at regular intervals as specified by the cron under Schedule. So this option is redundant.
Now coming to the hook, is it configured to deliver everything or just the push event? You can hit http://<jenkins_url>/log/all in your browser to see the system log while pushing changes. Towards the bottom of this log, see if Jenkins has received the hook and poked the job. If the hook is not received, reconfigure it at GitHub to send the appropriate events. Else, delete and recreate the job as sometimes Jenkins fails to register a new job to poke on receiving events and at other times a new job itself doesn’t respond to poking.
It's enough to keep only GitHub hook trigger for GITScm polling on, because this is the right option for conditional triggers (following git push as opposed to scheduled as a cron job, i.e. proper polling 1).
As for ideas on how to get the triggering (not polling) started, consult my "pre-flight checklist" here, because it's not a trivial matter.
Side note: feel free to report it to the Jenkins Github Plugin devs if you also think that the word "polling" is misplaced in this option (as per the definition of this term).

How to exit Jenkins job if SCM polling does not detect any changes?

Windows Server 2016, Jenkins 2.107.1. We have GitHub repositories, Git repositories not in GitHub, and CVS repositories. This link...Can I restrict poll SCM job to be run only once in a day?, tells me that I can set the polling to happen only once a day (which is all that we want, in that the coders can check in, up to a certain time). It does not tell me how to exit out (not to continue with the rest of the build steps), if there are no changes (and, send out a message that there are no changes and thus will be no build tonight). We are not using pipeline. Thanks.
the poll scm plugin in by default will not run the job if there are no SCM changes, also you will get GIT polling logs to see the detailed information

In Jenkins, if next trigger build is in pending state then how to abort running build and start running next pending build?

In Jenkins, If one build is currently running and next one is in pending state then what should i do so that running one should get aborted and next pending one should start running and so on.
I have to do it for few projects and each project has few jobs in it, I tried to save build_number as env variable in one text file (build_number.txt) and take that number to abort previous triggered build but making build_number.txt file for each job is not looking efficient and then I have to create many build_number files for each job for every project.
Can anyone please suggest me some better approach
Thanks
Based on the comments, if sending too many emails is the actual problem, you can use Poll SCM to poll once in 15 minutes or so, or even specify quiet time for a job. This will ensure that build is taken once in 15 minutes. Users should locally test before they commit. But if Jenkins itself is used for verifying the commits I don't see anything wrong in sending an email if build fails. After all, they are supposed to know that, no matter even if they fixed it in a later update intentionally or unintentionally.
But if you still want to abort a running job if there are updates, you can try the following. Lets call the job to be aborted as JOB A
Create another job that listens on updates same as that of the job that needs to be aborted
Add build step to execute groovy script
In the groovy script use Jenkins APIs to check if JOB A is running. If yes, again use APIs to abort the job.
Jenkins APIs are available here

Resources