AZ-400: Designing and Implementing Microsoft DevOps Solutions

Design and Implement Pipelines

Pipeline triggers

In this article, we dive deep into Azure Pipeline Triggers and demonstrate how they streamline and automate your CI/CD workflows. Learn how to enhance your development process by understanding the four primary trigger types in Azure Pipelines.

Overview

Pipeline triggers are critical components in any CI/CD process. They automate the initiation of build and deployment pipelines based on defined conditions, ensuring efficiency from code commit to production deployment. Azure Pipelines supports four primary trigger types:

  1. Continuous Integration (CI) Triggers
  2. Pull Request (PR) Triggers
  3. Scheduled Triggers
  4. Manual Triggers

Each trigger plays a unique role in automating your pipelines and maintaining a robust development lifecycle.

The image shows four types of triggers: Continuous Integration (CI) triggers, Pull Request (PR) triggers, Scheduled triggers, and Manual triggers, each represented with a distinct color and icon.

Continuous Integration (CI) Triggers

Continuous Integration Triggers automatically start a build whenever source code is pushed to a repository. This immediate reaction to code modifications is essential for maintaining a fast-paced and agile development environment.

The image illustrates a Continuous Integration (CI) trigger process, showing a flow from "Code" to "Repository" with an automatic build initiation when code is pushed.

In Azure DevOps, CI triggers monitor specific branches within your version control repository. For instance, when a developer pushes a commit to the main branch, the CI trigger initiates a build and testing sequence to quickly surface any issues.

Consider this YAML snippet for configuring a Continuous Integration Trigger in an Azure Pipeline:

trigger:
  branches:
    include:
      - main
      - feature/*

This configuration means:

  • The trigger block specifies which branches will start a pipeline run when changes are pushed.
  • The main branch is explicitly included, ensuring that any push triggers the pipeline.
  • The feature/* wildcard pattern triggers the pipeline for any branch that starts with "feature" (e.g., feature-NewLogin, feature-UpdateDatabase).

This setup is widely used in development workflows to validate both production-ready code and ongoing feature developments continuously.

Pull Request (PR) Triggers

Pull Request triggers are designed to automatically validate code changes when a pull request is created or updated. When a pull request is submitted, Azure DevOps can run a build and execute tests against the proposed changes, helping to ensure that new code integrates seamlessly with the existing codebase while maintaining quality standards.

The image illustrates a CI/CD pipeline triggered by pull requests, with a note indicating that the pipeline starts automatically when a pull request is created or updated.

This automated validation plays a crucial role in enforcing code review policies and preserving overall code quality.

Scheduled Triggers

Scheduled triggers enable pipelines to run at predefined times or intervals without manual intervention. This feature is particularly useful for routine tasks such as nightly builds, weekly integration tests, or daily deployments to staging environments.

Below is an example configuration for a scheduled trigger in a YAML pipeline:

trigger: none # Disables the automatic CI trigger
schedules:
  - cron: "0 0 * * *" # Cron format: minute, hour, day of month, month, day of week
    displayName: Daily Midnight Build
    branches:
      include:
        - main # Specifies that the schedule applies to the main branch
    always: true # Runs the pipeline even if no code changes were detected

This cron-based schedule ensures that your pipeline executes at the designated time consistently.

In classic pipeline setups, the scheduled trigger configuration is similarly intuitive:

The image shows a screenshot of a scheduled trigger setup in a classic pipeline, with options to enable the trigger and set specific days and times for release. It includes a section for adding new times and displays the current schedule as Monday through Friday at 3:00 AM UTC.

Manual Triggers

Manual triggers provide the flexibility to execute a pipeline on-demand. Users can start these triggers via the Azure DevOps interface or through the Azure CLI. Manual triggers are especially useful for operations that need human oversight, such as deployments to production, initiating rollbacks, or handling special scenarios that fall outside the regular automated processes.

The image shows a slide titled "Manual Triggers – Use Case" with two sections: "On-Demand deployments" and "Manual approvals," each with an icon.

Best Practices

Adopting best practices when configuring pipeline triggers can enhance the efficiency and reliability of your CI/CD workflows.

Best Practice Reminder

  • Selective Branch Triggering: Limit triggers to relevant branches to avoid unnecessary pipeline executions.
  • Conditional Execution: Use conditions within your pipeline configuration to finely control when pipelines run.
  • Manual Approvals: Incorporate approvals, especially for sensitive or production environments, to add an extra layer of oversight.

By following these guidelines, you can ensure that your pipelines are both efficient and robust, supporting high-quality code and seamless operations.

The image lists best practices for using triggers, including being selective with branches, using conditions to control pipeline execution, and incorporating manual approvals for sensitive environments.

For more detailed insights into Azure Pipelines, visit the Azure Pipelines Documentation.

Watch Video

Watch video content

Previous
Maintainability