CI/CD pipeline - schedule cron expression 1st monday of the month is misinterpreted

Dear all, in my ci I would like to trigger jobs at a differente date. To do so, in the cicd schedule section I create 4 different schedule; For some reasion the cron expressions I use are misinterpreted; You can find them below and test them under: or any website you like.

In gitlab the schdule for the 1st monday of the month will be execute in 4 days :confused: ; I’m confused as we are today the 18th of Octover.

To reproduce this behaviour, you can:

  • create a new schedule in one of your repo under: build > pipeline_schedules
  • you can copy past one of the cron expression below and choose your time_zone
  • add a description (name of your schedule)
  • select activated

I obviously miss something; Could you please point me to the good direction here ?

Thanks inadvance for your time and help on this subject.

# ## 1st_monday_of_the_month -- 0 2 1-7 * 1   -- "At 02:00 on every day-of-month from 1 through 7 and on Monday."
# ## 2nd_monday_of_the_month -- 0 2 8-15 * 1  -- "At 02:00 on every day-of-month from 8 through 15 and on Monday."
# ## 3rd_monday_of_the_month -- 0 2 16-23 * 1 -- "At 02:00 on every day-of-month from 16 through 23 and on Monday."
# ## 4th_monday_of_the_month -- 0 2 24-31 * 1 -- "At 02:00 on every day-of-month from 24 through 31 and on Monday."

As gitlab-ci you can use something like this:

    - if: $CI_COMMIT_BRANCH != "main" && $CI_PIPELINE_SOURCE != "merge_request_event"
      when: never
    - when: always

  - Test
  - UpgradeSystem


  stage: Test
    - echo "check server availability"

  stage: UpgradeSystem
    - 1st_monday_of_the_month # see schedules section for details
    - echo "upgrade os on dc1"

  stage: UpgradeSystem
    - 2nd_monday_of_the_month # see schedules section for details
    - echo "upgrade os on dc2"

@orsius83 Welcome to the forum!

Adding an & after the day of the week for each cron line in the Scheduled Pipelines will resolve this. There is some additional information in the repository for the extension being used that explains further why the command will be run when either day of the month or day of the week match. I found that link from the GitLab docs about cron.

I hope this helps!

-James H, GitLab Product Manager, Analyze:Product Analytics

1 Like

Thanks @ jheimbuck_gl! :slight_smile:

I try your solution and it seems to work;

  • Run once a month on the 1st Monday: 0 2 1-7 * 1&` :white_check_mark:

I also received a response from another person who proposed me to use the following syntax:

  • Run once a month on the 2nd Monday: 0 0 * * 1#2 :white_check_mark:

Choosing this approach, we could use multiple β€œcron” in once:

  • all in once (1st, 2nd, 3rd and 4th Monday of the month: 0 2 * * 1#1,1#2,1#3,1#4 :x:

BUT infortunately should work as expected :frowning: ; probably a bug :confused: