How to Use Cron Syntax in Jenkins for Scheduling Jobs
In Jenkins, use
cron syntax in the 'Build Triggers' section under 'Schedule' to run jobs at specific times. The syntax has five fields: minute, hour, day of month, month, and day of week, separated by spaces. For example, H 12 * * 1-5 runs a job at a random minute during 12 PM on weekdays.Syntax
The Jenkins cron syntax uses five fields separated by spaces:
- Minute (0-59)
- Hour (0-23)
- Day of Month (1-31)
- Month (1-12)
- Day of Week (0-7, where both 0 and 7 mean Sunday)
Each field can be a single number, a range (e.g., 1-5), a list (e.g., 1,3,5), or a special character like * for any value. Jenkins also supports H to distribute load by hashing job names to a consistent time.
plaintext
MIN HOUR DOM MON DOW 0 12 * * 1-5
Example
This example schedules a Jenkins job to run every weekday at 12 PM at a hashed minute to spread load:
plaintext
H 12 * * 1-5
Output
Job runs once every weekday at 12:XX PM, where XX is a consistent hashed minute between 0 and 59.
Common Pitfalls
Common mistakes when using cron syntax in Jenkins include:
- Using six fields instead of five (Jenkins uses five fields only).
- Confusing day of month and day of week fields; if both are restricted, the job runs when either matches.
- Not using
Hto avoid all jobs running at the same time, which can overload the server. - Using
0 0 * * *expecting it to run at midnight UTC, but Jenkins uses the server's local time.
Wrong: 0 0 * * * * (six fields, invalid)
Right: 0 0 * * * (runs daily at midnight)
plaintext
Wrong: 0 0 * * * * Right: 0 0 * * *
Quick Reference
| Field | Allowed Values | Description |
|---|---|---|
| Minute | 0-59 | Minute of the hour |
| Hour | 0-23 | Hour of the day |
| Day of Month | 1-31 | Day of the month |
| Month | 1-12 | Month of the year |
| Day of Week | 0-7 | Day of the week (0 or 7 = Sunday) |
Key Takeaways
Jenkins cron syntax uses five fields: minute, hour, day of month, month, and day of week.
Use
H to spread job start times and reduce server load spikes.Avoid six-field cron expressions; Jenkins only supports five fields.
If both day of month and day of week are restricted, the job runs when either matches.
Jenkins schedules jobs based on the server's local time, not UTC.