Jenkins : Scheduling Jenkins Jobs for a specific time

Jenkins uses a cron expression, the different fields are :

  1. MINUTES Minutes in one hour (0-59)
  2. HOURS Hours in one day (0-23)
  3. DAYMONTH Day in a month (1-31)
  4. MONTH Month in a year (1-12)
  5. DAYWEEK Day of the week (0-7) where 0 and 7 are sunday

Since a few versions, Jenkins add a new parameter, H : (extract from the jenkins code documentation)

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.

Note also that :

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.

Example 1 : H H(3-4) * * *  : A job which runs every Day of the week, every Month in a year , every Day in a month at a time between 3 – 4 am in the morning at any minute.

Example 2 : H (30 -45) 3 * * * : A job which runs every Day of the week, every Month in a year , every Day in a month at 3 am in the morning between 30 -45 minutes.

Example 3 : */5 * * * * : If you want to shedule your build every 5 minutes, this will do the job

Example 4 : 0 8 * * * : schedule your build every day at 8h 00, this will do the job 

Have fun as you work!

See Also: Parameterised Scheduler Plugin

cool-jenkins2x3

Regards,

VJ

7 responses to “Jenkins : Scheduling Jenkins Jobs for a specific time

  1. good morning.
    I need to know if it is possible that the values for the crontab are received as variable. For example, to execute the build you request, hour minutes, day, month and day of the week, as execution parameters. Then those values, pass them as variables to crontab. Is this possible?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s