Jenkins: build one job after another with some delay - jenkins

I have 2 jobs in Jenkins: QA and Dev.
In Dev job I checked "Build after other projects are built" option and set project name = QA so that QA job will be built after Dev job is built.
But in my particular situation I need that QA job started building in 5 mins after Dev job is built. How can I do it? maybe I can add some build step with some data to add this delay ?
TIA,
Anna

There is a "Quiet Period" option in the Advanced Project Options available. You can enter a value of 300 (its in seconds) to delay the start of the job by 5 mins.

If you're using the REST api, you can add a url get value like this:
http://jenkins/job/jobname/build?delay=4
That will delay 4 seconds and start the job.

I know the topic is quite old but in case sameone else is looking for an answer here it is.
When using parametrized build remember to escape "&". You can replace it with: "%26" or put the whole URL in quotes. It will work. Please also remember to use delay as first parameter.

To make it simpler with out worrying about trigger from URL using delay, there is a Jenkins plugin which helps to schedule the job on the fly with as much as delay you need (configurable when ever you are running build and supports parameterized builds as well). For more details please check Plugin Pags, GitHub

Related

Jenkins: Trigger a future build once a job is completed

I can't seem to find the best way to do that.
I have a Jenkins job I ran manually (say a job that creates a temporary file somewhere).
I want to be able to clean this up (e.g. delete the temporary file) after 2-3 hours.
I was thinking adding a Post Deploy action that will run a job with some parameters + some delay. But I can't find anything like that.
I've noticed several schedule plugins or REST API options, but nothing that as simple as "When Succesfully Building A, Build B in X minutes".
Suggestions?
Suggestions?
You could exploit the Quiet period.
job1 -> (sleep -> fake-job) -> job2
so let job1 trigger the fake-job whch has a quiet period of 7200 seconds and this fake-job will trigger your cleanup job.
You can use Parameterized Trigger Plugin (https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin).
Here you can pass predefined parameter to Project to build like sleep_time parameter and you can handle it in triggered Jenkins job. Also you can configure Trigger build on Stable / Unstable / always trigger conditions.
I hope it will be useful for you.

How can I incorporate a long delay into a Jenkins build process?

I am using Jenkins to deploy changes to a system which manages and runs lots of different jobs which are scheduled daily. We have a staging setup which does not write to the real database, and a production setup which does.
The Jenkins flow I would like to have a happen when a change is pushed is this
Run checks.
Deploy to the staging system.
Wait 24 hours.
Check logs to make sure that the staging system has not had any errors in the last 24 hours.
Deploy to the production system.
There could be more than one of these builds running concurrently at any time - eg. I push changes at 11 am, they are deployed to staging. At 5 pm I push more changes and they are also deployed to staging. The next day at 11 am the first set of changes only are deployed to prod. At 5pm that day the second set of changes are deployed.
Now, I have managed to build a system which does this, by using the Build Flow Plugin, and creating a job called wait_one_day which runs sleep $((24 * 60 * 60)) in a bash shell.
This doesn't seem like the most elegant solution, and has the disadvantage that I am tying up two Build Executors for 24 hours (one for the build flow job, and one for wait_one_day), each time we make a change.
Is there any better way of doing this, or any plugin which is designed to help with this process? Can a Jenkins job schedule another Jenkins job to run as a one-off?
I would equally be happy to hear about an alternative approach to solve the same problem if anyone has any suggestions or constructive criticism of my design.
There was similar SO question recently that I answered, although I'm not sure that my answer there exactly fits your scenario.
You could potentially dynamically create a job that does steps 4 & 5 which would run periodically every 24 hours. The catch here is that you would actually only run this job once, and have a build step in that job that deletes itself (groovy code or shell script). It would be easy enough to create a deactivated template job that you could just clone and then modify for the particular task. An intermediary job would be necessary which would trigger upon completion of any job that runs steps 1 and 2. The intermediary job would then create the temporary job from the template.
Alternatively, you could create some sort of handler, either within jenkins or external that would run off of some properties file or database containing the scheduling for when jobs need to be fired off. Granted, if you are going to go the route of writing a handler, you might consider putting in a little extra effort and writing a jenkins plugin...

Jenkins - Triggering Scheduled Jobs

Is there a way to trigger a scheduled job?
I am building a pipeline of connected jobs which trigger each other once complete. I want one of the jobs to be scheduled to run at a particular time of the day. So I want to be able to essentially add to a queue to trigger at a later time.
Is that possible?
Cheers
To schedule a Jenkins job to run at a specific time, go to the job's landing page, click Configure from the left-side menu, scroll down to 'Build Triggers' section and pick 'Build Periodically'.
There you can specify the cron job formatted string to denote when and how often you'd like this first job to be scheduled for running.
If that job is not the first job in line, you can always use 'Quiet Period' option under 'Advanced Project Options' which puts in a delay in that job before the build steps actually run. You can specify the number of seconds you want that job to wait for before it actually executes.
This plugin seems to be piggybacking on the 'Quiet Period' feature though I haven't tried it myself: https://wiki.jenkins-ci.org/display/JENKINS/Schedule+Build+Plugin. You might have luck using it to your advantage.
You could use the Jenkins Workflow plugin suite (mentioned in your tag, perhaps unintentionally). It has a sleep step. If you wanted the next stage of the pipeline to run at a particular time of day, rather than after a fixed interval, you could do some simple computation with java.util.Calendar to determine the seconds between now and then.

How to fire an alert when a Jenkins job runs for too long?

I want to be alerted when my Jenkins jobs run for too long.
I didn't find such a plugin, do you know of such a plugin, or another way to do it?
Thanks!
As far as I know there is no such plugin or configuration available. There is buildtimeout-plugin, which will abort the build on a given timeout, but AFAIK doesn't support just giving an alert and not aborting.
if you're willing to make a custom build of the plugin, it might be reasonable to extend that yourself. Like you can see from its source code, it defines a general BuildTimeoutOperation interface which should be extendable to give an alert on build timeout instead of aborting a build. The existing implementations of the interface could give you some ideas on how that would be done.
Try this,
For sound & mail alert :
-> Use Jenkins Sounds plugin & build triggers to achieve your task.
Create a separate job for alert and trigger the job when you want. (stable, unstable or failed)
In that same job itself, you can configure email notification.
To find long running job, Use parallel (time counter configuration or use build-timeout plugin) job. If it takes time more than specified then trigger an alert job (configured with sound or email)

How can I configure execution start between dependent jobs?

My Jenkins server is set up with two jobs A and B say.
Job A is triggered from changes in subversion, runs unit tests and if successful, creates a WAR and deploys it to another environment.
If Job A succeeds, then Job B triggers. This job runs tests against the deployed WAR.
The problem is that the deployment process takes a while and the WAR is not ready in time for when Job B starts and tries to use it.
I'm looking for ideas on how to delay Job B until the WAR is up and running.
Is there a way, once Job B is triggered to wait for x seconds? I really don't want to put it into the tests in Job B if I can avoid it.
Thanks
There is definitely a way for a job to wait - just put sleep into the first shell build step. Alternatively, you can set 'Quiet period' - it's in Advanced Project Options when you create a build.
That, however, is a band-aid solution to be employed only if other approaches fail. You may try the following: if there is a way to make the deployment process (that job A triggers) right before it finishes to touch a file that Jenkins has access to, then you can use FSTrigger Plugin. See use case 3 there.
The most reliable way to make this work would be to make job A not complete until the deployment is successful, e.g. by testing for a valid response from the URL of the deployed web app. This blog post describes one way to do that.

Resources