Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get a Jenkins trigger to run every first week day of every month?

My goal is to trigger a report every first weekday of the month at 7AM (7/1/15,8/3/15,9/1/15, etc.)

I am using the following cron expression: H 7 1-3/3 * 1-5

It runs on July 1, but it is not scheduled next to run on August 3, but on September 1. How can I get it to run on the first weekday of every month?

I am using the following help guide:

MINUTE Minutes within the hour (0–59)
HOUR The hour of the day (0–23)
DOM The day of the month (1–31)
MONTH The month (1–12)
DOW The day of the week (0–7) where 0 and 7 are Sunday.

To specify multiple values for one field, the following operators are available. In the order of precedence,

  • The * specifies all valid values
  • M-N specifies a range of values
  • M-N/X or */X steps by intervals of X through the specified range or whole valid range
  • A,B,...,Z enumerates multiple values

To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible.

like image 703
Fly Guy Avatar asked Jul 01 '15 16:07

Fly Guy


Video Answer


1 Answers

First weekday of the month rules:

  • If today is a Monday, then the job should be run if today is also the 1st, 2nd, or 3rd of the month
  • If today is a Tuesday, Wednesday, Thursday, or Friday, then the job should be run if today is also the 1st of the month

The following cron expressions should do the job:

H 7 1-3 * 1
H 7 1 * 2
H 7 1 * 3
H 7 1 * 4
H 7 1 * 5
# Would last have run at Wednesday, July 1, 2015 7:00:02 AM EEST; would next run at Monday, August 3, 2015 7:00:02 AM EEST.

Beware, because of this article, you can't just use:

H 7 1-3 * 1
H 7 1 * 2-5

The above doesn't work! Instead, the job is run on every weekday, twice on the 1st of the month, and maybe twice on the 2nd and 3rd of the month!

But I was not able to reproduce it.

like image 97
Vitalii Elenhaupt Avatar answered Sep 29 '22 14:09

Vitalii Elenhaupt