I want to set Jenkins to run a job every 3rd minute, but not starting at 0. Basically, I have 3 jobs and I want to cycle through them each minute.
The first job I can run every 3rd minute with */3 * * * *. But the second I tried 1/3 * * * * and it failed with hudson.remoting.ProxyException: line 1:2: unexpected token: /
How do I write this expression?
I think you're looking for:
job 1: 0-57/3 * * * *
job 2: 1-58/3 * * * *
job 3: 2-59/3 * * * *
Think of the cron minute entry as meaning "range/step" (or, "run this every step minutes over the minute range start-end)
Reference: I was able to figure it out from this excellent answer, which includes some helpful related links and a more in-depth explanation.
Related
I am trying to understand when this trigger runs in Jenkins groovy script. Seems to me that Jenkins groovy script has some DSL for cron. Does anyone know when this cron job is triggered?
triggers {
cron('H 5 * * 7')
}
In H 5 * * 7 the H means hash. You can have digit in the first place, but H allows to distribute the load better.
H = minute when less load is expected, Jenkins will propose it the first time, after that it will stay more or less the same, if there are available agents to handle it.
5 = hour,
* = any value (every day),
* = any value (every month),
7 = 7th day of week (Sunday).
Reference:
Spread load evenly by using ‘H * * * *’ rather than ‘5 * * * *’
You can test it using the CRONTab tester.
This means to start at 5:00 on every sunday
https://crontab.guru/#0_5_*_*_7
I want to schedule a jenkins job every 3 hours but exclude 6 o'clock. Something like the following statement which unfortunately is not possible in Jenkins:
H (0-5,7-23)/3 * * *
If I use the following statement it is treated separately:
H 0-5/3,7-23/3 * * *
Hence, the job starts at 0 o'clock even if the previous job was executed at 22 o'clock.
The worst solution would be to specify all times manually. Is there any better way?
You will need to explicitly set the hours.
So if you want to skip 6 PM then Jenkins corn will be
H 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,23 * * *
and if you want skip 6 AM then
H 0,1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * *
Schedule Jenkins Build Execution During Specific Times using Build periodically: (* * * * * *)?
For example: * * * * * * will execute builds continuously,
Is there a way to use the above approach but to run builds continuously between lets say 9am until 11pm.
Example:
Monday: time of execution: 9am until 11pm.
Tuesday: time of execution: 9am until 11pm.
To run jobs between 9am - 11pm every day, you could use the following:
* 9-23 * * *
To run jobs between 9am - 11pm only on Monday, you can use:
* 9-23 * * 1
And likewise for Tuesday:
* 9-23 * * 2
This website is a great resource for experimenting with cron job formats, and seeing a "human translation" for the syntax.
I think you can use the following cron expression : H 9-23 * * *
To build your own new cron expression keep the following link handy and test in Jenkins:
https://www.freeformatter.com/cron-expression-generator-quartz.html
How can I run a job created in Jenkins every one minute ? Am I missing anything?
PS: I'm trying not to use: */1 * * * *
Try * * * * * to run every minute.
Unfortunately H/1 * * * * does not work due to open defect.
Defect: https://issues.jenkins-ci.org/browse/JENKINS-22129
Your intuition is right, H/1 is supposed to behave like "run every minute".
However, there is a well-known bug in Jenkins. See JENKINS-22129.
Currently, H/1 behaves like "run every hour".
Use this format it will Run a Jenkins job every one minute "* * * * *"
To run the build process every minute,
check the Build periodically option and add * * * * *
I made jobs to start at every 4 hours H */4 * * *
But I can't schedule at 4:10
I tried 10 */4 * * * and H/10 */4 * * *
Unfortunately no luck
Configuring a fixed time is very simple:
10 4 * * *
Your 10 */4 * * * means "run it every 4 hours, at minute 10".
See also http://www.adminschoice.com/crontab-quick-reference/ for reference.
EDIT
Sorry, from the description it seems you want to run it at exactly 4.10, but I then realized that in the title you say something different: every 4h and 10'. Do you mean e.g. at [1.10, 5.20, 9.30]? If so, try */10 */4 * * *.
Please provide an example with a sequence of times you expect, e.g. [2.10, 3.20, 4.30], so that it's more clear what you want.