Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I schedule a job to run in the future, but only one time ever

Tags:

jenkins

I want to schedule a job that will execute at most once at a specified time in the future (usually that time would just be later that night, after hours). I want to use Jenkins to do this. If Jenkins happened to be down during that time, the job wouldn't fire - that's fine.

At the moment, I'm planning to make a new job with "build periodically" enabled, and set the schedule to something like "0 19 29 01 *".

The intent being to schedule the job to run at 19:00 on the 29th of January.

The downside being that every time I do this, I must remember to delete/disable the job sometime before next year, or it will run again (that would be bad). I'd be checking the results of the job manually anyway, so not too hard to do. I'm just hoping someone might be able to point out a way to schedule a "one off" job run with Jenkins - that way I can't mess things up by forgetting to disable the job.

like image 850
Shorn Avatar asked Jan 27 '16 05:01

Shorn


1 Answers

Install the "Schedule Build Plugin". "Adds capability to schedule a build for a later point in time. Asks the user for a date and time and adds the build to the build queue with the respective quiet period."

Restart jenkins seems to be needed after plugin install even though you see the icons for a scheduled build.

https://wiki.jenkins-ci.org/display/JENKINS/Schedule+Build+Plugin

BEWARE: After initial install (with jenkins 2.2) I got a warning "plugin offered a GET". There did appear to be some sort of a job scheduled and it said it "expires in 13hr" which was correct for the time I scheduled. It did not run the job. :-(

The warning seen:

You must use POST method to trigger builds. (From scripts you may instead pass a per-project authentication token, or authenticate with your API token.) If you see this page, it may be because a plugin offered a GET link; file a bug report for that plugin.

Url, presumably the GET:

http://jenkins:xxxx/job/jobname/build?delay=47212sec

This was with Jenkins 2.2 and Schedule Build Plugin 0.3.4

I have it working now for me jenkins 2.7.4 and Schedule Build Plugin built from source.

Solution: Use latest jenkins and wait for new release of plugin (>0.3.4) . . . (or build from source). There is already a bug open on the plugin for the GET problem and a fix in source code but not yet in latest release. 26/Sep/2016: https://issues.jenkins-ci.org/browse/JENKINS-28961 Building schedule_build.hpi from source this plugin works. For jenkins 2.2 it worked IF CSRF Protection is disabled in jenkins.

like image 78
gaoithe Avatar answered Oct 19 '22 04:10

gaoithe