Search code examples
jenkinscron

How to configure Jenkins job to run every 45 minutes?


I am trying to configure a Jenkins job to run every 45 minutes:

*/45 * * * *

But the latest intervals of the running job don't look fine to me ever since I changed it:

Mar 27, 2020 11:45 AM
Mar 27, 2020 11:00 AM
Mar 27, 2020 10:45 AM
Mar 27, 2020 10:00 AM
Mar 27, 2020 9:45 AM
Mar 27, 2020 8:36 AM
Mar 27, 2020 7:36 AM
Mar 27, 2020 6:36 AM

As you can see, before changing the interval, the job ran once every hour.
I actually expected the output to be like this:

Mar 27, 2020 12:45 AM
Mar 27, 2020 12:00 AM
Mar 27, 2020 11:15 AM
Mar 27, 2020 10:30 AM
Mar 27, 2020 9:45 AM

What's wrong with my configuration?


Solution

  • You are running your job every 45 minutes within an hour. Each hour is handled separately and counter starts over.

    Simplest fix is to change interval to hour or 30 minutes (in general to something that divides an hour without reminder) - this way you'll have even intervals without extra effort. Con is obvious - frequency is not exactly what you wanted.

    Other way is to set intervals to smaller value (like 15 minutes) and check time in job (and exit job if time didn't pass yet). Con is that you need extra logic in job and that you have "empty" builds in history.

    Last option is to set every trigger manually - 32 triggers a day for "every 45 minutes". It can be quite compact for some intervals (like 45 minutes), but in case you wanted to change it to "every 41 minutes" it becomes a mess.