DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Chaining API Requests With API Gateway
  • 5 Key Concepts for MQTT Broker in Sparkplug Specification
  • What Is React? A Complete Guide
  • Building a Flask Web Application With Docker: A Step-by-Step Guide

Trending

  • Chaining API Requests With API Gateway
  • 5 Key Concepts for MQTT Broker in Sparkplug Specification
  • What Is React? A Complete Guide
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Schedule Pipelines in Azure DevOps Using Cron Expressions

Schedule Pipelines in Azure DevOps Using Cron Expressions

This article helps you with an easy way to trigger pipelines using Cron Expression or Jobs in Azure DevOps. A step-by-step tutorial is helpful for beginners.

Ganesh Hegde user avatar by
Ganesh Hegde
CORE ·
Jun. 30, 21 · Tutorial
Like (1)
Save
Tweet
Share
22.78K Views

Join the DZone community and get the full member experience.

Join For Free

Azure DevOps UI provides an option to trigger multiple days or once a week. We know that many times we need to execute Azure DevOps pipeline triggers once a month, or twice a month, and this can be done using Cron Expressions in Azure DevOps.

Azure DevOps uses NCronTab to evaluate cron expressions, so advanced expressions are not fully supported by Azure DevOps. However, most of the expression is supported so it does the job.

In this tutorial, I have explained step by step how to configure Cron Scheduler in Mircosoft Azure DevOps.

The tool NCrontab Expression Tester is very helpful to evaluate cron expressions, especially when we consider Azure DevOps. There are many tools I suggest not using because when I tried on that the tool it evaluated successfully but it caused an error in Azure DevOps. The reason is Azure DevOps is supporting only NCronTab basic expressions since the tool is built on the same which is helpful to us. Let's say thanks to this guy.

Step-by-Step Guide to Schedule Pipeline Build or Release using Cron Job or Cron Expressions

Let’s consider my requirement is I want to schedule build First Sunday of every month.

There are two things you need to consider here:

  1. The pipeline which you have already created, let’s say some deployment release pipeline (Example: MyRelease Pipeline).
  2. The new Pipeline (let's call it as Scheduler Pipeline this is build) triggers the above Pipeline, i.e., MyRelease Pipeline (Pipeline mentioned Point No. 1).

In a simple way, Scheduler Pipeline triggers the MyRelease Pipeline.

In other words, you have already created the MyRelease Pipeline (Point no. 1) and you are looking for that pipeline to be triggered in specific intervals that will be done by Scheduler Pipeline.

Let’s see how to trigger My Release Pipeline from Scheduler Pipeline.

Step 1: Create a New Pipeline, i.e., Scheduler Pipeline

Navigate to Azure DevOps page > Hover on Pipelines > Choose Pipelines.

Pipelines on Azure DevOps Page

Step 2: Click on New Pipeline

Once you clicked on Pipelines, The New Pipeline window appears. Here click on the New pipeline.

New Pipeline on Pipelines Page

Step 3: Where is Your Code? Section: Choose Use Classic Editor (Refer to Image)

Once you complete step 2, you will be asked to choose the source of your code. Choose Azure Repos Git as your source.

Where Is Your Code? Options

Step 4: Choose Desired Project and Repository

Your YAML file will be saved in this location, so choose as per your requirement.

Choosing Desired Project and Repository

Step 5: Choose Template as YAML

When the Choose Template window appears, choose Start pipeline from the list.

Once you are done with Step 5, the default YAML file will be created and it looks like the below image.

Created YAML File From Step 5

Step 6: Remove the Unwanted Line From The Default Script

Please note that pool: option I am giving is ubuntu-latest. This might change in your organization, you can specify as per your requirement. So, type the correct agent pool in the pool: section.

Removing Unwanted Line From Default Script

Step 7: Click on Show Assistant

Azure DevOps YAML pipeline comes with an assistant, This helps you fill the required details in the text box and it will be added as YAML script. To get the assistant click on right most section show the assistant option.

Review Your Pipeline YAML > Show Assistant Button

Step 8: Search and Select the Release Orchestrator

Once you click on show assistant the assistant opens up, in the search box type 'Release Orchestrator'. The release orchestrator task shows up at the beginning choose that.

Finding and Choosing the Release Orchestrator

Step 9: Enter Details for Release Orchestrator Task

As I have shown below image, enter the correct details as per your project details:

Project Name: <Choose the correct one>
Definition Name: <Choose the Release Pipeline Name>
Release Strategy: Click on Create, or you can choose Other if you wish.
Definition Stages: <Choose from Stage options>

Entering Release Orchestrator Details

Step 10: Click on Add

Once you click on Add from the Release Orchestrator task the entry -task will be added to your YAML file

Result of Adding Release Orchestrator

Step 11: Add Cron Job Details

As per the Microsoft Azure DevOps document below is the syntax to add cron expression.

YAML
 
//Cron Job Syntax for Azure DevOps, This is Just a syntax not an actual code.
schedules:
- cron: string # cron syntax defining a schedule
  displayName: string # friendly name given to a specific schedule
  branches:
    include: [ string ] # which branches the schedule applies to
    exclude: [ string ] # which branches to exclude from the schedule
  always: boolean


Considering the above syntax, you need to construct Cron Job Schedules like below.

YAML
 
schedules:
- cron: "0 2 1-7 * SUN"
  displayName: 25th 5:30 AM (IST) Every Month
  branches:
    include:
    - master


Note:

1. I have mentioned 0 2 1–7 * SUNthat means the first Sunday of every month.

2. If are not sure how to build the cron expression read the details on Azure DevOps Cron Syntax for Azure Pipelines. 

3. Once you construct the Cron Expression validate here for correctness. NCrontab Expression Tester this tool tells you exact dates as per your cron expression.

Your Complete YAML File

Once you complete all the steps your code looks like below. 

YAML
 
schedules:
- cron: "0 2 1-7 * SUN"
  displayName: 25th 5:30 AM (IST) Every Month
  branches:
    include:
    - master
pool:
  vmImage: 'ubuntu-latest'
steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'
- task: releaseorchestrator@2
  inputs:
    endpointType: 'integrated'
    projectName: 'My Project'
    definitionName: 'MyRelease Pipeline'
    releaseStrategy: 'create'
    definitionStage: 'Staging'



Completed YAML File


Step 12: Click on Save and run Button

Once you click on Save and run, Azure DevOps Triggers the mentioned Release as per Scheduled Timing which we mentioned in the Cron Syntax.

Location of Save and Run Button


Encourage me to write more articles, buy a coffee for me.

If you are looking for any help, support, guidance contact me on LinkedIn|https://www.linkedin.com/in/ganeshsirsi/.

azure Pipeline (software) Crons DevOps Schedule (computer science)

Opinions expressed by DZone contributors are their own.

Trending

  • Chaining API Requests With API Gateway
  • 5 Key Concepts for MQTT Broker in Sparkplug Specification
  • What Is React? A Complete Guide
  • Building a Flask Web Application With Docker: A Step-by-Step Guide

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: