Kamuip1823
Kamuip1823

Reputation: 9

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

Upvotes: 0

Views: 1895

Answers (2)

Vince Bowdren
Vince Bowdren

Reputation: 9208

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.

Upvotes: 1

Daniël J.M. Hoffman
Daniël J.M. Hoffman

Reputation: 2137

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

Upvotes: 0

Related Questions