35

I have a job with as cron:

5 3,21 * * 1-5

This will run my job at 03:05AM and 09:05PM. Now I read it's a best practice to use H.

I try:

H/5 3,21 * * 1-5

What is the meaning now? Will this schedule a build in a range of 5 minutes or 5 minutes after 3AM and 21PM?

DenCowboy
  • 13,884
  • 38
  • 114
  • 210
  • Modern versions of Jenkins will tell you what the "next" and "previous" launches will be. Change the setting and look at the window below it. E.g. with `H/20 * * * *` it says this `Would last have run at Sunday, June 5, 2022 at 6:03:23 PM Coordinated Universal Time; would next run at Sunday, June 5, 2022 at 6:23:23 PM Coordinated Universal Time.` – Steven the Easily Amused Jun 05 '22 at 18:20

1 Answers1

71

The H will take a numeric hash of the Job name and use this to ensure that different jobs with the same cron settings do not all trigger at the same time. This is a form of Scheduling Jitter

H/5 in the first field means Every five minutes starting at some time between 0 and 4 minutes past the hour

So H/5 3,21 * * 1-5

is Every five minutes between 03:00 and 03:59 and then between 21:00 and 21:59 on Mon -> Fri but starting at some 'random' time between 03:00 and 03:04 and then the same number of minutes after 21:00

If you want to run once per hour between 03:00-03:59 and 21:00-21:59 on Mon -> Fri, you can use H 3,21 * * 1-5 where H will be replaced by some number between 0-59 depending on job name.

The user interface will tell you when the job will last have triggered and will next trigger

Spangen
  • 4,420
  • 5
  • 37
  • 42
  • So this does not mean start between 2.55 and 3.05 a build AND start a build between 20.55 and 21.05? – DenCowboy Nov 15 '17 at 08:37
  • H/5 3,21 * * 1-5 is telling me it would start a build around 3AM and around 21PM (not between them). But thanks for the info. I understand now I think. You can edit it and I'll accept – DenCowboy Nov 15 '17 at 08:42
  • But H/5 will do it every 5 mins during the hours 3:xx and 21:xx. If you want it just once in those hours just use H on its own – Spangen Nov 15 '17 at 08:43
  • You're right. Is it possible to run it like I described in my initial case but using 'H'? So run it twice around 3AM and around 9PM? – DenCowboy Nov 15 '17 at 08:56
  • Correct "Around" means "Between 0 and 59 minutes after" It won't run at 02:59 . If you're happy with my answer would you mind marking it as accepted? – Spangen Nov 15 '17 at 09:01
  • Thanks, I think I need something like: H(0-5)/1 21 * * 1-5 (run between 5 minutes after 9PM? – DenCowboy Nov 15 '17 at 09:03
  • 3
    The /1 will try and run it every minute. I think `H(0-5) 21 * * 1-5 is what you're after – Spangen Nov 15 '17 at 09:14
  • What would happen if ‘different jobs with the same cron settings do all trigger at the same time’ – Henson Fang Feb 28 '20 at 06:20
  • It might contend for resources with your available agents. – Spangen Feb 28 '20 at 09:46