Azure Pipelines Schedule to Run Only Few Days a Month - azure-devops

Is there a way to customize the pipeline scheduling options in Azure to have it run only the second week of each month?
I know you can schedule it to run on individual days of the week, but I cannot figure out how I would do this on a monthly scale.

Can I do this if my pipeline was made as a classic/GUI based, and not
as a YAML pipeline?
In the classic pipelines, you can only set scheduled triggers for each week. As far as I know, you can not have it run only the second week of each month in the classic pipelines. However, you can set schedule triggers in yaml pipeline and use it to trigger your classic pipeline.
Here is the sample if you are going to use a YAML pipeline:
schedules:
- cron: "0 0 8-14 * *"
displayName: schedule
branches:
include:
- main
always: true
In this example:
The pipeline will be triggered from the 8th to the 14th of this
month. You need to update the date each month.
always: true means run even when there are no code changes.
Agree with iikkoo that if you want to run your pipeline by only using scheduled triggers, you must disable PR and continuous integration triggers by specifying pr: none and trigger: none in your YAML file.
You can add a build completion trigger in this yaml pipeline to trigger your classic pipeline:
Please find more detailed information about Configure schedules for pipelines in the document.

You can achive this by creating a scheduling trigger in your YAML config. Note tough, you must disabled PR and CI triggers to run your pipeline by using scheduled triggers.
You disable the trigger by setting pr: none and trigger: none. Then you define the schedule using cron syntax.
schedules:
- cron: "0 0 1/14 * *" # At 00:00 on every 14th day-of-month from 1 through 31.
displayName: Second week of each month
branches:
include:
- master
...
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml
https://github.com/atifaziz/NCrontab/wiki/Crontab-Expression
https://crontab.guru/

It doesn't seem to do so in the UI, but you can still trigger the build via an API call on your own schedule.
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-6.1

Related

Why is my Devops pipleline being triggered by the completion of another pipeline, despite me replacing the pipeline trigger with a schedule only

I have a pipeline that is being automatically triggered upon completion of another pipline despite me removing the code from the YAML that should be responsible for this.
Taking it back to the beginning: I have created 3 yaml Pipelines. Originally Pipeline 1 was configured for a Scheduled Trigger only. Pipeline 2 was triggered by completion of Pipeline 1. Pipeline 3 was triggered by completion of Pipeline 2. These pipeline triggers were defined in the yaml. Below is an example of the relevant snippet from Pipeline 3's "original" yaml
trigger: none
resources:
pipelines:
- pipeline: Pipeline2 .
source: Pipeline2
trigger:
branches:
include:
- integration
However I then decided that I did not want to do this, and I removed the above code block and replaced it with the below:
trigger: none
schedules:
- cron: "35 1 * * 1-5"
displayName: Daily Schedule
branches:
include:
- main
always: true
Below shows that no triggers have been configured via the GUI
However Pipeline 3 is still being triggered by completion of Pipeline 2....Can someone please help me understand why my Pipeline is triggered by anything other than the schedule?
Below is a screenshot of the build summary
I have resolved this. It appears to have been a bug. When I updated my YAML to remove the pipeline trigger block and merged it across all the branches, Devops appears not to have updated my pipeline to remove this trigger.
To fix the problem I simply deleted the pipeline and recreated it, pointing at exactly the same YAML file and setting exactly the same default branch. I did nothing else and now my pipeline is no longer being triggered by another pipeline

Schedule trigger option in Azure DevOps mechanism

I understand that regardless of commit in the VCS , if highlighted option below is selected then build would trigger as per the scheduled event. Am I correct?
What will happen when we don’t select below option? Provided in 2 scenarios with commit & with out commit?
enter image description here
You can find an explanation here: Running even when there are no code changes
By default, your pipeline does not run as scheduled if there have been
no code changes since the last successful scheduled run. For instance,
consider that you have scheduled a pipeline to run every night at
9:00pm. During the weekdays, you push various changes to your code.
The pipeline runs as per schedule. During the weekends, you do not
make any changes to your code. If there have been no code changes
since the scheduled run on Friday, then the pipeline does not run as
scheduled during the weekend.
To configure the scheduled pipeline to build only if there has been a
change since the last build, check Only schedule builds if the source
or pipeline has changed.
You configured pipeline for scheduled runs. It will run according to your schedule, irrespectively of whether commit happened or not.
You might be interested in commits-based triggers, which are Continuous Integration (CI) triggers and configured separately
Here are some examples for CI triggers in pipeline YAML file:
# specific path build
trigger:
branches:
include:
- master
- releases/*
paths:
include:
- docs
exclude:
- docs/README.md

Azure DevOps - Running scheduled task with existing CI pipeline

If I wanted to run a scheduled task once a month for checking for outdated dependencies but I already have a CI pipeline how can I do that? For example I have a pipeline that runs though code sniffs -> checkmarx + twistlock -> deploy to dev -> stage and whatnot. This triggers on master. I want to also include the ability to have a scheduled task of dependabot to occur once every month. How can I mix this scheduled task into an established CI pipeline? This is all contained within Azure Devops as well.
I only want to run the single task of dependabot once a month. I don't want to run the entire pipeline once a month
I suggest creating a second - entirely separate - pipeline to run dependabot once a month.
That way, you can have the appropriate triggers for the CI pipeline, and the appropriate schedule for the dependabot pipeline, with exactly the right tasks in each one and no duplication.
You can run a pipeline using both the trigger and schedules.
For example, to run a stage on the 1st day of every month at 08:00 UTC, you can use:
trigger:
- master #This is the trigger for other stages. It is not needed for the scheduled stage.
schedules:
- cron: '0 8 1 * *'
displayName: 'Deploy every 1st day of every month at 08:00Z'
branches:
include:
- master
always: true
Then, to ensure that a specific stage runs as part of the scheduled run, use the condition expression, for example:
- stage: 'Test'
displayName: 'Deploy to the test environment'
dependsOn: Dev
condition: eq(variables['Build.Reason'], 'Schedule')
Refer to this MSDocs article for more on the syntax of schedules: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml#scheduled-triggers

Azure cron scheduled pipeline always running (without failing builds)

Azure scheduled pipeline runs for every push in master.What am I missing?Here's the yaml code:
schedules:
- cron: "0 23 * * *"
displayName: Nightly build
branches:
include:
- master
Apparently, the previous builds aren't failing.
I've already tried to remove this pipeline and create it again, but it keeps running for every push.
The scheduled runs are correct:
Ok, I think I figured this out.
Just added the following lines to the yml file and it no longer runs the scheduled pipeline on every push.
trigger: none
pr: none

Scheduled build job on azure devops stopped scheduling new builds

Had a scheduled job running every 30 minutes of Azure devops, it was running fine, last scheduled build I saw was on 2019-10-02·14:00, and since then there were no changes made to azure devops or even to the repository for which the pipeline builds.
Devops is not triggering any new builds, not sure about the issue and where should I look for issues.
Tried a manual run, thinking that it could invoke the sleeping process somewhere, but it did not help
trigger:
branches:
include:
- master
schedules:
- cron: "*/30 * * * *"
displayName: Daily half-hourly build
branches:
include:
- master
always: true
....
....
For your issue ,there could be two reasons why the schedule trigger stopped scheduling new builds.
The first one : Set the schedule trigger in UI
Scheduled triggers defined using the pipeline settings UI take precedence over YAML scheduled triggers.
If your YAML pipeline has both YAML scheduled triggers and UI defined scheduled triggers, only the UI defined scheduled triggers are run. To run the YAML defined scheduled triggers in your YAML pipeline, you must remove the scheduled triggers defined in the pipeline setting UI.
The second one: Each cron schedule has a limit
Each cron schedule has a maximum of 100 pipeline runs per week.From your description: running every 30 minutes, it should exceed the limit of 100 pipelines per week. If you need more, you can split your cron schedule into multiple cron schedules that each result in 100 or less pipeline runs per week.
You can check these two points to see if this is the cause of the issue.For details please refer to this official document.