Jenkins periodic build - jenkins

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

Related

How to make a cycled sequence of jobs in Jenkins?

I'm new to Jenkins. I have a stack of 5 different jobs. I want them to execute endlessly, meaning the first one will start after successfull finish of 5th. Is there a way to do this? Is Jenkins pipeline plugin the right tool to make this?
If you already have 5 non-pipeline jobs, the easiest way is to
set a downstream job on each job as it makes a loop.
In the configuration page of each job, Add post-build action > choose Build other projects > Enter a name of a downstream job.
in pipeline there is a build step (https://jenkins.io/doc/pipeline/steps/pipeline-build-step/), but I haven't tried if this can take trigger itself (most probably).

How to trigger a Jenkins job by another job at a certain time?

I have two jobs, JobA and JobB, JobA runs every day at 13.00 and registers some payments. I want JobA to trigger JobB which verifies the payments, if and only if JobA is successful and JobB needs to be run the next day at 04.00
Any idea how to do this?
BR
I have not been able to find anything that will do this out of the box. You can, of course, schedule a job to build periodically, but that's not all that you want.
You could try one of these 2 ideas (I have not implemented either myself).
Set JobB to build periodically at 4am, but deactivate the job. Create an intermediary job with a build trigger to build if JobA is successful (e.g. set JobA in the projects to watch section). The intermediary job would run code to activate JobB - groovy code using the groovy plugin would be easiest, or you could use the rest api via shell / batch script. Then as the last build step in JobB, run a similar script to deactivate the job again.
The Schedule Build Plugin allows you to schedule future builds. However, it appears that this is a manual process. If you can figure out how to programatically fire off a scheduled build through this plugin, you could add that code to an intermediary job that is setup in the same way as mentioned in option #1.
You can use build job: step in pipeline (https://jenkins.io/doc/pipeline/steps/pipeline-build-step/) and quite period in seconds to trigger the job at required time.
EDIT:
The way i did
def currentDate = GregorianCalendar.getInstance()
If you want next day at 5 am
def plannedDate = new GregorianCalendar(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DAY_OF_MONTH) + 1, 5, 0)
def quietPeriod = (plannedDate.getTime().getTime() - currentDate.getTime().getTime())/1000

Jenkins to run 10 jobs sequestially and few parallely and only run jobs what I choose

Jenkins to run 10 jobs sequentially and few parallely and let say 1-2 jobs are successful and job3 failed. I fixed the job3.Now I want to again trigger the job but only want to trigger it from job3.All 10 jobs have string parameter.
I can pick an choose what jobs to trigger. how can I achieve it.Please help.
The whole point of CI is to have multiple runs frequently, so that in next run you can see them all stable. Not sure why you wanted to do this. However, You can take 2 approaches.
You can use conditional Step plugin along with multiphase plugin,
wrap you build step with condition and pass whether you want to run
it or not. only if the condition is passed then the individual jobs
will be triggered.
You can use jenkins-cli and trigger the jobs
which ever you wish.

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

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.

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