Azure Pipeline Triggers Simplified

Azure Pipelines is a cloud-based service that helps automate the building, testing, and deployment of applications. One of the most important features of Azure Pipelines is its ability to trigger pipeline runs automatically. Pipeline triggers are used to start a pipeline run automatically whenever certain events occur, such as code changes or the creation of a new pull request.

In this article, we will explore the different types of pipeline triggers available in Azure Pipelines and how to use them. We will also discuss some common use cases for pipeline triggers and answer some frequently asked questions about this feature.

The above schema shows you resources that is a top-level YAML keyword that defines a list of resources to be used in the pipeline. Each resource can be of a different type, such as pipelines, repositories, or packages. Here, we are defining a pipeline resource.

Under pipelines, we have a list of pipeline resources. For each pipeline resource, we specify a pipeline_name and a pipeline_source. The pipeline_name is a user-defined name for the pipeline resource, and pipeline_source is the name of the pipeline to be triggered by this resource.

Under trigger, we specify the conditions that trigger the pipeline when there’s any change in the specified source pipeline. 

  • The branches keyword also specifies a list of branches to trigger the pipeline when changes are made.¬†
  • Tags keyword specifies a list of tags to trigger the pipeline when changes are made.
  • Paths specifies a list of file paths to trigger the pipeline when changes are made to those files.¬†

The include and exclude keywords allow you to filter files by name or extension, to limit the scope of changes that trigger the pipeline. Using this schema, you can define Resource Triggers to automatically trigger pipeline runs when changes occur in other pipelines or resources, making your pipeline more efficient and automated.

Types of Pipeline Triggers

Azure Pipelines supports several types of pipeline triggers, each designed to handle different scenarios. Let's take a closer look at each type of trigger and when to use them.

Continuous Integration (CI) Trigger

The most common type of trigger is the Continuous Integration (CI) trigger. This trigger is used to build and test your code every time changes are pushed to the repository. The CI trigger can be configured to run on specific branches or on all branches.

Use cases: When you want to run your build and tests automatically every time code changes are pushed to the repository.

Scheduled Trigger

The Scheduled trigger allows you to run a pipeline on a schedule. You can set a specific time and frequency for the trigger to run, such as every day at 6:00 am or every week on Fridays at 9:00 pm.

Use cases: When you want to run your pipeline at a specific time or interval, such as running nightly backups.

Pull Request Trigger

The Pull Request trigger is used to automatically build and test code changes that are submitted through pull requests. This trigger ensures that any code changes are tested before they are merged into the main branch.

Use cases: When you want to ensure that any code changes are tested before they are merged into the main branch.

Code Change Trigger

The Code Change trigger is used to run a pipeline when a specific file or folder in your repository is changed. This trigger can be configured to run on specific files or folders.

Use cases: When you want to run your pipeline only when a specific file or folder is changed, such as running tests only when changes are made to the backend API.

Manual Trigger

The Manual trigger allows you to manually start a pipeline run. This trigger can be useful when you need to run a pipeline outside of the normal triggering events, such as running a one-time deployment.

Use cases: When you want to run a pipeline manually, such as deploying a new release to production.

Webhook Triggers

Webhook triggers in Azure Pipelines allow you to automatically trigger pipeline runs based on external events, such as changes to a GitHub repository, a new Docker image being pushed to a container registry, or a new release being created in Azure App Service.

To use webhook triggers in Azure Pipelines, you need to create a webhook in the external service that will notify Azure Pipelines when the event occurs. When the webhook is triggered, Azure Pipelines will automatically start a pipeline run based on the webhook's configuration.

Define webhook triggers for your pipeline that are triggered automatically when external events occur, allowing you to automate your pipeline and streamline your software development process.

Configuring Pipeline Triggers

Now that we've discussed the different types of pipeline triggers, let's take a look at how to configure them in Azure Pipelines.

To configure a trigger, navigate to your pipeline and click on the "Edit" button. Then, click on the "Triggers" tab to see the available trigger options.

From here, you can select the trigger type and configure the trigger settings. For example, to configure a CI trigger, select the "Continuous Integration" option and choose the branch(es) you want the trigger to run on.

Common Azure Pipeline FAQs

Q: Can I configure multiple triggers for a single pipeline?

A: Yes, you can configure multiple triggers for a single pipeline. For example, you can configure a pipeline to run on a schedule and also run when changes are pushed to the repository.

Q: Can I disable a trigger without deleting it?

A: Yes, you can disable a trigger without deleting it. To do this, go to the "Triggers" tab and click on the trigger you want to disable. Then, toggle the switch next to "Enable" to "Off".

Q: How can I see the history of pipeline runs triggered by a specific trigger?

A: In Azure Pipelines, you can easily view the history of pipeline runs triggered by a specific trigger. This can help you track the status and progress of your pipeline and identify any issues or errors that may have occurred.

To view the history of pipeline runs triggered by a specific trigger, follow these steps:

  1. Navigate to your pipeline and click on the "Edit" button.
  2. Click on the "Triggers" tab to see the list of triggers configured for your pipeline.
  3. Click on the trigger for which you want to see the history of pipeline runs. On the trigger configuration page, you will see a section labeled "Recent runs". This section shows a list of the most recent pipeline runs triggered by this trigger.
  4. Click on any of the pipeline runs listed to see more details about that run, such as the start time, duration, and status. You can also click on the "All runs" link at the bottom of the "Recent runs" section to see a full list of all pipeline runs triggered by this trigger.
  5. From the "All runs" page, you can filter the list of runs by status, date range, and other criteria to help you find the specific runs you are interested in.

Additionally, you can use the Azure DevOps REST API to programmatically retrieve the history of pipeline runs triggered by a specific trigger. This can be useful if you want to automate the process of tracking pipeline runs or integrate pipeline run data with other tools or systems.

To retrieve the history of pipeline runs triggered by a specific trigger using the REST API, you can make a GET request to the following endpoint:

In this URL, replace {organization} and {project} with the names of your Azure DevOps organization and project, respectively. Replace {pipelineId} with the ID of your pipeline, and {triggerId} with the ID of the trigger you want to view the history for.

When you make this request, the API will return a JSON response containing a list of pipeline runs triggered by the specified trigger, along with details about each run such as the run ID, status, and start time. You can parse this response in your application or script to extract the data you need.

To see the upcoming scheduled runs for a particular pipeline, you can access the Kebab Menu (three dots) and click on the "Scheduled runs" option. You can also view completed Scheduled Triggers by selecting the "Trigger Runs" option and then clicking on "Schedule".

PS: If you set up your Azure DevOps YAML Triggers using both the UI settings and CRON syntax, the UI settings will take priority over your syntax. If you want to define YAML Triggers using CRON, you need to remove any Scheduled Triggers defined in your Pipeline Settings UI.

However, simply using Azure DevOps, might not be enough to get the best out of your project space, an engineering analytics tool can equip you with the data-driven insights you need to place your team on top. Hatica offers metrics across 13 dashboards, powered by CI/CD tools, Jira, GitHub, Azure, CircleCI and GitLab. By collating tool activities at one place, Hatica helps teams streamline their workflow and improve productivity.

Subscribe to the Hatica blog today to read more about unblocking developers, and boosting productivity with engineering analytics. 

TL;DR

Subscribe to Hatica's blog

Get bi-weekly insights straight to your inbox

Share this article:
Table of Contents
  • Types of Pipeline Triggers
  • Continuous Integration (CI) Trigger
  • Scheduled Trigger
  • Pull Request Trigger
  • Code Change Trigger
  • Manual Trigger
  • Webhook Triggers
  • Configuring Pipeline Triggers
  • Common Azure Pipeline FAQs
  • TL;DR