I have a Jenkins job which is scheduled for a specific time. I want to modify that timing programmatically.
I tried to modify the build by installing Schedule Build plugin and modify it using http://jenkins_url/job/jobname/build?delay=3344sec
. But this will put the job in quiet period which holds the java thread. I'm looking to modify the Schedule entry without putting it to quiet period.
You can find the URL to call to interact with the Jenkins system with the REST API link in the bottom right hand corner of each screen: In this example, we want to trigger the build of a Jenkins project, so we open the project and find the REST API link points us to a URL like http://jenkinsserver/jenkins/job/Run%20a%20script/api/.
Jenkins schedule format Under Build Triggers - Build periodically - Schedule you can create a schedule (or multiple schedules) for Jenkins to build periodically or on a specific date/time. It might be tests that should be run periodically (every morning for example) or a DB clean up Jenkins job or any other Jenkins job.
A Jenkins server – for this tutorial, we'll use the official Docker image to set up a Jenkins server Login in to your Jenkins application and click on Create a Job. The type of job doesn't matter. It can be Freestyle, Maven, etc. All that matters is how we configure the scheduler. For this article, we'll go with Pipeline.
There are many ways to trigger a Jenkins job: manually (of course), using a Cron Expression, hooks, watching other projects, etc. Let's start with triggering a job via the Cron utility. We'll choose Build periodically and for the Schedule field use the following expression:
You can use the Build Triggers -> Build periodically
job configuration option. Use that to specify the exact time for starting a new build.
If you need to change that time, use the Jenkins REST API to...
In bash, this can be done with a one-liner (using curl
and sed
) to modify the XML section below (the example schedules a run for noon, Feb 29):
[...]
<triggers>
<hudson.triggers.TimerTrigger>
<spec>00 12 29 02 * </spec>
</hudson.triggers.TimerTrigger>
</triggers>
[...]
Note:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With