Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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) * * *
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top