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.
Related
I am trying to see if there is a plugin that can do what I want or something I am missing with regards to Jenkins triggers. To give you an example of what we want to do let me explain how things are happening currently.
A merge is made
Jenkins picks up on merge, pulling changes on remote build machine
Server is stopped
Build, checks, etc are done
Server is started
So the above is all well and good and working, however what we want to do is trigger the server stop and build after the merge is picked-up by Jenkins. Here is the catch though, it is a large project, with multiple tracks and we could have say 4-10 merges done within a 10-30 minute window. So obviously we do not want to have 4-10 jobs in the queue all running the same thing.
So what would be the best approach to achieving the above, i.e. Jenkins triggers based on merge, say waits for x minutes, if no other merges, then triggers the build process, if new merge reset counter back to x minutes and wait again?
Are there any plugins or triggers built into Jenkins that we can achieve this with? (I couldn't find anything obvious) Or is this a case we need to parameterise the build and have some script running?
Not aware of any plugin which does this. But if you're using the job type Pipeline or willing to convert it to Pipelines, then the following Jenkins pipeline will do the trick:
// Sleep for a certain time, in this case 20 seconds
sleep(20);
// Check if there is a newer build, if there is abort this one.
if (currentBuild.nextBuild != null) {
echo "Got newer build, aborting this one!"
currentBuild.result = Result.NOT_BUILT;
return;
}
// Do the rest of building here
You can run the below command from URL and it serves the purpose.
https:///build?delay=600sec
I have a Jenkins job that should not start building until another job has been built successfully at least once. They are not related per se, so I don't want to use triggers. Is there a way to do this?
Some background: I'm using SCM polling to trigger the second job. I've looked at the Files Found Trigger plugin, but that would keep on triggering the second job after the first on has been built. I've also found the Run Condition Plugin, but that seems to work only on build steps, not on the entire build.
Update - The second job copies artifacts from the first job. As long as the first job has never completed successfully, the Copy Artifact step fails. I am trying to prevent that failure, by not even attempting to build the second job until the first job has completed once.
One solution is to use the Build Flow plugin.
You can create a new flow job and use this DSL:
I've used 10 in the retry section but you can use any numbers.
This flow job can be triggered by monitoring the same SCM URL of your second job.
Update, here is a second solution.
You can use the HTTP Request plugin.
If you want to test that your first job has been built successfully at least once, you can test this URL:
http://your.jenkins.instance/job/your.job/lastSuccessfulBuild/
One example:
As my build has never been successful, the lastSuccessfulBuild URL doesn't exist. The HTTP Request changes my build status to failure.
Does it help?
The Block queued job plugin can be used for this: https://wiki.jenkins-ci.org/display/JENKINS/Block+queued+job+plugin
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.
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
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.