NOTE: This feature is primarily for using Jenkins as a cron replacement, and it is not ideal for continuously building software projects. […] the point of continuous integration is to start a build as soon as a change is made, to provide a quick feedback to the change.1
In Jenkins go to:
Configure -> Build triggers -> Build periodically -> Schedule
Let’s say you want to run it:
– at 3 a.m.,
– from Monday to Friday,
– each day of the month,
– any month of the year,
then it would be best if you had the following syntax:
Crone syntax0 3 * * 1-5
where:
– 0 means minutes
– 3 – is 3 a.m.
– * means days of months
– * means all months in the year
– 1-5 means from Monday to Friday
NOTE: Better syntax you can use (you will get the following warning):
Spread load evenly by using ‘H 3 * * 1-5’ rather than ‘0 3 * * 1-5’
Jenkins syntax (recommended)H 3 * * 1-5
So, why H 3 * * 1-5
?
- Load Distribution: Jenkins uses
H
to spread out jobs across a time window, reducing the chance of system overload at exact times. - Consistency:
H
ensures that even though the minute is random, it is consistent across builds for a given job.
By using H 3 * * 1-5
, Jenkins will run the job at a random minute within the 3rd hour (between 3:00 and 3:59 AM), Monday to Friday, but it won’t trigger multiple jobs at exactly 3:00 AM.
Let’s see what the documentation says about running it periodically:
This field follows the syntax of cron (with minor differences). Specifically, each line consists of 5 fields separated by TAB or whitespace:
MINUTE HOUR DOM MONTH DOW
MINUTE | Minutes within the hour (0–59) |
HOUR | The hour of the day (0–23) |
DOM | The day of the month (1–31) |
MONTH | The month (1–12) |
DOW | The day of the week (0–7) where 0 and 7 are Sunday. |
To specify multiple values for one field, the following operators are available. In the order of precedence,A,B,...,Z
enumerates multiple values*
specifies all valid valuesM-N
specifies a range of vauesM-N/X
or */X
steps by intervals of X through the specified range or whole valid rang
- Jenkins – Help for feature: Build Periodically ↩︎