Excluding a job from the Jenkins Job Queue when a build is in progress - jenkins

I have a long-running job (10 hours) scheduled to run twice a day (at 11am/11pm).
I generally only want to commence the build at 11am/11pm.
If the previous build fails, I sometimes want to start the next build early (e.g. 9am).
How do I do it? If I manually kick off the build at 9am, the scheduled build will go into the queue at 11am, and will execute as soon as the first build completes. I don't want that, if I manually start, I want to skip the scheduled build.
Another way of thinking of it ... I want to ignore a scheduled (or manual) build request if there is a build in progress.

To do what I'm wanting I've added the following into conditional build steps at the start and end of the job, conditional on the Build Cause of UserCause.
jenkins.model.Jenkins.getInstance().getItem('Test').disable();
jenkins.model.Jenkins.getInstance().getItem('Test').enable();

Peter,
https://wiki.jenkins-ci.org/display/JENKINS/Run+Condition+Plugin
Above plugin will be useful for you.kindly go through the documentation.

Try this Plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Block+queued+job+plugin
It will allow you to block job when last build is in progress.

Related

Showing pending build everytime when manually buid in jenkins

The scenarios is like:
Initially we scheduled 3 jobs in jenkins named like core, api-simulator and ui-sumilator. core is main build and triggered build once in week. api-simulator and ui-simulator are dependent. Once core is executed, it triggered other both jobs. So we can say core is parent of other two.
Somehow, someone changed the build triggered rule for core job and set it to 3 times in everyhour. So it executed so many task for core job. Meanwhile it triggered job for other two also.
To stop all those executions, I disabled all 3 jobs.
But now we are facing issue like when we manually click on build now, it starts building but eveytime it generated next task also. If we keep it running, it will generate new schedule one by one continuously.
Even I created new job for same repository and tried but facing same issue.
screenshot of execution
Can anyone have an idea how to stop that auto triggered schedule task or remove all those task?
Seems to be, that you've configured triggering your downstream jobs from main job and at the same time in your child jobs you've configured main job as upstream job.
So, re-check your configuration, and if that - you need to disable upstream job in child jobs.
Thanks #biruk1230 for your answer.
It has been resolved by just done the minor configuration change in Jenkins. I updated Branches to build value to "master". It was "*/master" previously.
You can view from Reference link

Jenkins job that calls cyclically a script

I'm having some difficulties in getting this one working.
How would I have to configure a job in Jenkins to call some script on a node, the node to execute and when exiting, the job to not declare the build finished but to wait for a certain amount of time and to call again the script. The waiting period would have to be dynamically calculated at runtime based on a target start time. Such a build would have to be stopped by some user input and not by aborting the build.
I know pipelining might be needed in this case but I'm not very sure how the build history would look like as I intend to have only one build appearing in there not a bunch of builds spawned by the main one. Hopefully, I was able to make myself easy to understand.
Thank you very much.

Jenkins periodic build

Is there a possible to prevent the full jenkins job from running, that is periodically scheduled; if there is no SCM changes since the last build.
For example,
There is a daily night build, to create a build. The completion of this job triggers(upstream project) the automation testing job for that build.
I would like to be able to have two things
Stop the 1st build job, if there is no SCM change since the last job
2nd upstream automation test job runs only if it has not run for 1 week. (after it has been triggered by the 1st Job)
Thanks in advance
The first part is simple, instead of "Build periodically" set to "Poll SCM" with the same schedule. It's exactly what it does: periodically checking for changes and only running the job if there were some.
The second part (triggering another job with a time constraint) is more complicated. One option is "Throttle builds" (to 1 per week) in addition to your usual build triggering scheme. Another one is "Trigger builds remotely (e.g., from scripts)" option and checking whether required conditions are met in some sort of script or service.
For the first
Did you try the poll the SCM every night? If no changes, the Jenkins job wont start.
0 23 * * *
Will run every night at 11 p.m
for the second
use the following plugin : https://wiki.jenkins.io/display/JENKINS/Run+Condition+Plugin

How to execute only the most recent queued job in Jenkins?

I've got a commit build project in Jenkins which schedules an acceptance build project on completion. Since commits come in faster than the acceptance build job finishes, after a short time there are now six queued acceptance build jobs. I would like the acceptance build project to work like the "Poll SCM" functionality - On completion, start the most recently queued job, skipping the rest.
I can't use the "Build after other projects are built" without more hacks since I need to pass information from the commit build job to the acceptance build job.
#l0b0,
Jenkins behavior is to coalesce builds so that the queue only contains the currently running build and one enqueued job. The depth only increases if the newly enqueued jobs takes parameters that differ from what's already on the queue.
So I'm gathering that your downstream (acceptance) job takes some sort of parameters, but you need to supply more details of how it's working.
If you're using parameterized trigger plugin then you should check out this existing SO thread
More generally speaking, you should look into your parameters. It sounds like you are passing too much information from upstream to downstream jobs, resulting in the the Jenkins queue treating them as distinct parameters when then is not necessarily the case.
Are you passing in the run number of the last successful upstream job as a parameter? If so, then yeah you've got problems. What you should do instead is use the Promoted Build Plugin on the upstream job to mark the last successful build, and then have the downstream job simply jump to the most recent promoted build.
Hope that helps.

How can I get Jenkins SCM polling to accumulate changes?

I have a job that takes a while to complete and is quite resource heavy. I only ever want to run one instance of the job at a time, and only if there are new SCM changes.
I set it up with an SCM trigger and left off the checkbox "Execute concurrent builds if necessary".
The problem I have is that it queues up the next build on the first SCM change it detects.
What I want is that whenever the SCM trigger sees a change, that it replaces the job it queued up with a new job, with the newer SCM revision. I don't want it running a new instance with the next change, and I don't want a ton of jobs queued up.
Basically, I want the job to run in a loop, and only pause if there are no SCM changes.
How do I do that?
You might be looking for Quiet period option which is under Advanced Project Options section.
You can set the value (in seconds) for Quiet period as per your requirement. This will help you reduce the frequency of builds.

Resources