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

2

5

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?

Simulation answered 19/6, 2013 at 15:25 Comment(1)
The issue in the Jenkins JIRA: issues.jenkins-ci.org/browse/JENKINS-18313. As of now (April 2015) it's still unresolved.Cazares
V
8

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

Virginiavirginie answered 20/6, 2013 at 2:7 Comment(0)
D
3

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) * * *
Downe answered 26/4, 2019 at 7:59 Comment(1)
This should be the accepted answer. By the way US/Hawaii is deprecated, use Pacific/Honolulu instead.Sememe

© 2022 - 2024 — McMap. All rights reserved.