Nayden Van
Nayden Van

Reputation: 1539

Azure yaml trigger pipeline every 14 days on a Saturday

I have a little testing project that I will need to compile and build every 2 weeks specifically on a Saturday.

according to Microsoft Azure documentation I can use the schedules and set my cron, so I did as follow:

trigger : none
schedules:
  - cron: '* 8 1/14 * 6'
    displayName: Trigger every 2nd and 4th Saturday
    branches:
      include:
        - test
    always: true

But this is not working as I expected as in the Azure devOps I couldn't see the triggers.

Basically what I would like is for each month, this pipeline need to trigger on the 2nd Saturday and the fourth Saturday of the month (every 2 weeks on a Saturday).

As far as I understand from the documentations, is hard to set the days if they are not in a weekly basis, so tried with the hours. To test this I used crontab guru. Basically I counted how many hours there are in 14 days and set the cron as follow:

trigger : none
schedules:
  - cron: '* 8/312 * * *'
    displayName: Trigger every 2nd and 4th Saturday
    branches:
      include:
        - test
    always: true

But this for some reason it shows that the next trigger will be tomorrow at 8 in the morning.

I am quite confused at this point.

Did anyone have any advice how I can guarantee that the trigger will always falls on a Saturday every 2 weeks please?

Please, if my issue is not 100% clear, do not hesitate to ask more details.

Thank you so so much for any help you can provide me with.

Upvotes: 0

Views: 1501

Answers (3)

marksy
marksy

Reputation: 64

I asked ChatGPT and she reckons this would work:

0 8 * * 6/2

Breaking that down:

0: 00 minutes

8: 08 (am)

*: any day

*: any month

6/2: every Saturday, every 2 weeks

Upvotes: -1

Slideroh
Slideroh

Reputation: 41

I'd like to thanks @DavidCox88 2 years later. Azure Pipeline Devops is using different logic than you could test on crontab.guru

As above cron

0 8 8-14,22-28  * 6

would be triggered:

  • at 2024-06-29 08:00:00
  • then at 2024-07-06 08:00:00
  • then at 2024-07-08 08:00:00
  • then at 2024-07-09 08:00:00
  • then at 2024-07-10 08:00:00

So it would works as OR operator instead of AND - but for AzureDevops Pipeline it works as expected! Thanks again.

(Cannot add this as comment)

Upvotes: 0

DavidCox88
DavidCox88

Reputation: 1018

I believe you would want the following cron job

cron: 0 8 8-14,22-28  * 6

The logic behind this is the 2nd Saturday of the month must fall between days 8-14 and likewise the 4th Saturday to be between 22-28. You can test this by clicking the 3 dots on the pipeline and checking Schedule Runs. The problem with this is it only shows schedule runs within the next week so you would have to wait a while to confirm it works.

As a quick test to check the scheduling, if you use the above but modify it to run on a Wednesday ( as we are already past the 4th Saturday in this month) you can see that it will trigger once this week on the 28th

Upvotes: 3

Related Questions