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

Alois Mahdal picture Alois Mahdal · Jun 19, 2013 · Viewed 10.5k times · Source

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?

Answer

uncletall picture uncletall · Jun 20, 2013

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 ;)