How to schedule a Jenkins job every 3 hours but exclude a certain time frame - jenkins

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 * * *

Related

"H 5 * * 7" cron in Jenkins groovy script

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

Schedule a Jenkins Job to run hourly everyday but skip midnight (00:00) and resume again from 01:00 till 23:00

I have a Jenkins job which I would like to run from (01:00) 1 AM till (23:00) 11PM but skip midnight (00:00) and resume again from (01:00) on a daily basis. The thread How to schedule Jenkins job every Hour for the next 12 hours had this example H 9-21 * * * which i have changed to H 1-23 * * * to cater for my example.
Am I on the right track perhaps with using H 1-23 * * * ??
Yes, that should work. There is a cron tester you can look that will show you the cron version of that, and for Jenkins you just replace the 0 with the H.
http://cron.schlitt.info/index.php?cron=0+1-23+*+*+*+&iterations=50&test=Test

Jenkins job scheduler

How can I set Jenkins to run a job at a particular time?
Like if I'd like to set it to 8:30am every weekday and this is what I could do
H 7 * * 1-5
this randomly picks up 7:35am as running time.
H is a pseudo-random number, based on the hash of the jobname.
When you configured:
H 7
you are telling it:
At 7 o'clock, at random minute, but that same minute very time
Here is the help directly from Jenkins (just click the ? icon)
To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible. For example, using 0 0 * * * for a dozen daily jobs will cause a large spike at midnight. In contrast, using H H * * * would still execute each job once a day, but not all at the same time, better using limited resources.
The H symbol can be used with a range. For example, H H(0-7) * * * means some time between 12:00 AM (midnight) to 7:59 AM. You can also use step intervals with H, with or without ranges.
The H symbol can be thought of as a random value over a range, but it actually is a hash of the job name, not a random function, so that the value remains stable for any given project
If you want it at 8:30 every weekday, then you must specify just that:
30 8 * * 1-5
Take a look at http://www.cronmaker.com/
0 30 8 ? * MON,TUE,WED,THU,FRI *
30 8 * * 1-5
This would start at 8:30am Mon-Fri.
0 and 7 are Sundays.
Not sure what the H does but I am assuming it takes the lower case hex of h and applies 68 which is 35 in decimal... lol. Don't do that.
Following this format:
Minute Hour DayOfMonth DayOfWeek Day
It picks that time because you told it that it can, as imagine you already know:
minute, hour, day of month, month, day of week.
Now you have user H which allows Jenkins to pick at random. So you have told it to run between 7-8 every week day.
Change this to:
30 8 * * 1-5
Hope this helps!

How to schedule job in Jenkins every 4 hours and 10 minutes

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.

Schedule nightly 22-03 build using Jenkins and H, the "hash symbol"

A build that takes about three hours to complete needs to be scheduled for nightly building outside office hours: not sooner than 22:00 and not later than 3:59 next day.
I'd also like to use the "H symbol" to avoid collision with future nightly builds. From in-line help in Jenkins:
To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible. For example, using 0 0 * * * for a dozen daily jobs will cause a large spike at midnight. In contrast, using H H * * * would still execute each job once a day, but not all at the same time, better using limited resources.
(How) can I schedule this using Jenkins? What I've tried was all considered invalid by Jenkins:
H H(22,23,0,1,2,3) * * *
Invalid input: "H H(22,23,0,1,2,3) * * *": line 1:7: expecting "-", found ','
H H22,23,0,1,2,3 * * *
Invalid input: "H H22,23,0,1,2,3 * * *": line 1:4: unexpected token: 22
H H(22-3) * * *
Invalid input: "H H(22-3) * * *": line 1:9: 1 is an invalid value. Must be within 1
and -18
Is it possible to achieve this without using plug-ins?
I think the closest you will get is to use:
H H(0-3) * * * This will run at some point between 0:00 and 3:59
#midnight This will run at some point between 0:00 and 2:59
The H(4-8) construct only works if the second items is larger then the first.
But you might as well fill in the hour yourself. Jenkins actually never changes the hour the jobs runs once it is set. It will basically create some random hour once you save the job and always run the job at that particular time.
Of course, you can also file a bug report or feature request that you should be able to specify this as H(22-3) or better, fix the code and submit a patch ;)
There is no direct support to write the expression like this, but since there is timezone support (now), you can work around this.
# DONT COPY PASTE - THIS DOESNT WORK!
# This is what we would like to write, but is not supported
H H(22-3) * * *
Above expression means we want to build somewhen between 22 PM and 3 AM, this is a 5 hour period, so we could write:
# Assuming we're in GMT+2 we can just shift the timezone
# so 22-03 becomes 10-15 wich is 12 hours earlier so the
# timezone is GMT-10
TZ=Etc/GMT-10
H H(10-15) * * *
I found this workaround in the comments of JENKINS-18313
UPDATE:
There is currently a bug JENKINS-57702 and the timezone GMT-XX is not evaluated correctly. A workaround is to use a equivalent timezone, in this example the one for Hawaii:
TZ=US/Hawaii
H H(10-15) * * *

Resources