Meaning of H/5 in cron Jenkins

58,509

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

Share:
58,509

Related videos on Youtube

DenCowboy
Author by

DenCowboy

Updated on April 16, 2022

Comments

  • DenCowboy
    DenCowboy about 2 years

    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
    DenCowboy over 6 years
    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
    DenCowboy over 6 years
    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
  • Spangen
    Spangen over 6 years
    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
  • DenCowboy
    DenCowboy over 6 years
    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?
  • Spangen
    Spangen over 6 years
    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?
  • DenCowboy
    DenCowboy over 6 years
    Thanks, I think I need something like: H(0-5)/1 21 * * 1-5 (run between 5 minutes after 9PM?
  • Spangen
    Spangen over 6 years
    The /1 will try and run it every minute. I think `H(0-5) 21 * * 1-5 is what you're after
  • Henson Fang
    Henson Fang about 4 years
    What would happen if ‘different jobs with the same cron settings do all trigger at the same time’
  • Spangen
    Spangen about 4 years
    It might contend for resources with your available agents.