AZ-400: Designing and Implementing Microsoft DevOps Solutions

Design and Implement Pipelines

Pipeline triggers

Azure Pipeline Triggers automate the start of your build and deployment workflows when specific events or conditions occur. By using triggers effectively, you can streamline code validation, testing, and delivery across your CI/CD lifecycle.

Azure Pipelines supports four primary trigger types:

Trigger TypeDescriptionYAML Keyword
CIStart a build when code is pushedtrigger
PRValidate pull requests before mergingpr
ScheduledRun pipelines at defined times (nightly, weekly)schedules
ManualLaunch pipelines on demand via UI or CLIN/A

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 (CI) triggers automatically queue a pipeline run whenever new commits are pushed to selected branches. This immediate feedback loop helps catch build failures or integration errors early.

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 YAML pipelines, enable CI by defining the trigger section:

trigger:
  branches:
    include:
      - main
      - release/*
      - feature/*
  • trigger: activates CI-based runs
  • branches.include: lists branch patterns to watch
    • main builds production code
    • release/* handles hotfix or release branches
    • feature/* catches ongoing development work

Note

Wildcards (*) help you include entire branch families. To exclude specific branches, use exclude: under branches.

Scheduled Triggers

Scheduled triggers run pipelines at specified intervals or cron schedules—ideal for nightly builds, periodic tests, or routine deployments.

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 artifacts and setting a new schedule time.

To disable CI and add a schedule in YAML:

trigger: none              # Turn off CI-based runs
schedules:
  - cron: "0 2 * * 1-5"     # Weekdays at 02:00 UTC
    displayName: Weekday Early-Build
    branches:
      include:
        - main
    always: true           # Run even without new commits
  • trigger: none ensures only scheduled runs occur
  • cron: follows standard cron syntax (min, hour, dom, mon, dow)
  • always: true runs the job regardless of changes

Note

Cron schedules in Azure Pipelines are evaluated in UTC. Adjust your cron expression if your team operates in other time zones.

Pull Request (PR) Triggers

PR triggers automatically validate code changes when a pull request is opened or updated. This enforces quality gates before merging to protected branches.

The image illustrates a "Pull Request (PR) Triggers" concept, showing a CI/CD pipeline that automatically starts when a pull request is created or updated.

Example YAML configuration:

pr:
  branches:
    include:
      - main
      - develop
      - feature/*
  paths:
    exclude:
      - docs/**
  • pr: defines pull request validation triggers
  • branches.include: lists target branches for PR checks
  • paths.exclude: skips runs when only documentation changes

Manual Triggers

Manual triggers allow teams to start pipelines on demand for production rollouts, hotfix deployments, or ad hoc testing.

The image shows two use cases for manual triggers: "On-Demand deployments" and "Manual approvals," each represented with a colorful card and an icon.

You can invoke a manual run via:

  • Azure DevOps UI: Click Run pipeline and select parameters
  • Azure CLI:
az pipelines run \
  --name MyPipeline \
  --branch feature/hotfix \
  --variables deployEnv=staging

Warning

Manual deployments bypass automated gates. Ensure you have approvals or checks in place for sensitive environments.

Best Practices

Adopt these recommendations to keep your pipelines efficient and reliable:

  • Be selective with branch filters to reduce unnecessary runs.
  • Use path and tag filters to scope triggers precisely.
  • Combine CI, PR, and scheduled triggers for comprehensive coverage.
  • Implement manual approvals for production or compliance-sensitive deployments.
  • Regularly review and clean up stale schedules or branch patterns.

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.

References

Watch Video

Watch video content

Previous
Maintainability