0

I need to schedule a job in jenkins that runs every hour except that it should not run between 11:30pm and 4am. What would be the cron expression?

  • Hi, Welcome to Stackoverflow please read the community rules here https://stackoverflow.com/help/how-to-ask . Please use a search engine before asking a question. A quick search showed a similar question as yours https://stackoverflow.com/questions/12472645/how-do-i-schedule-jobs-in-jenkins . You can also use a crontab calculator like this one https://crontab.cronhub.io/ . Enjoy your time over here! – studioj Nov 20 '21 at 17:58

1 Answers1

0

This cron expression 0 4-23 * * 7 will run every day at the hour between 4AM and 11PM.

If you are not required to run this job at exactly when the hour starts, you can also use H 4-23 * * 7. H (for hash) is useful on Jenkins, as it will not execute all your scheduled jobs for the hour at exactly the same time, because it will try to even the load on the system (e.g. this job might run at 11.10PM).

Gergan Zhekov
  • 944
  • 1
  • 8
  • 27
  • Thanks for the comment. @Gergan Zhekov. What about the time from 23:00-23:30? – Franky Philip Nov 18 '21 at 09:47
  • Of course, that might also pick 11:43PM, so there's a compromise of picking a fixed minutes (0-29) or going past the half. The good news H is a hash (based on job name, plus ...?), so once established (and it will ahow next time to run) it's fixed. – Ian W Nov 18 '21 at 09:49