[

ūüéČ

G2 Spring 2024 Report] Hatica does it again! Wins Momentum Leader, Best Est. ROI and Users Love Us badge among many!Read More ->

Tools2023-04-19

Azure Pipeline Triggers Simplified 101

Discover the power of Azure Pipeline Triggers. Automate builds, track metrics, and streamline your software development with our comprehensive guide.
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.

What is Azure Pipelines Trigger?

Azure Pipeline Triggers offer an automated mechanism for initiating Azure Pipelines precisely when needed. Depending on manual intervention to launch a specific pipeline can be impractical, especially when you want to deploy pipelines during off-hours or holidays. By leveraging Azure Pipeline Triggers, users have the flexibility to configure pipelines to respond to internal or external events or to run on a scheduled basis, ensuring that tasks are executed at the optimal times.

When automated builds are set up to execute through Azure Pipeline Triggers or on a regular schedule, it is commonly referred to as Continuous Integration (CI) or Continuous Build (CB). The use of Azure Pipeline Triggers empowers users to adopt their DevOps workflows efficiently and automate their Continuous Integration and Continuous Deployment (CI/CD) processes.

Let’s jump into the types of triggers in Azure pipelines.

7 Types of Azure 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.

1. 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.

2. 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.

3. Resource Triggers

Resource Triggers are initiated by the resources specified within your pipeline, encompassing pipelines, builds, repositories, containers, packages, or webhook sources.

With Resource Triggers, you gain comprehensive visibility into the services employed within your pipeline, such as their versions, artifacts, linked modifications, and work items. Once a resource is defined, it becomes accessible throughout your Azure Pipeline. Moreover, through subscribing to trigger events associated with your resources, you can achieve full automation of your Azure DevOps Workflow.

4. 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.

5. 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.

6. 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.

6. 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.

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.

How to see the history of pipeline runs triggered by a specific trigger?

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:

Step 1: Navigate to your pipeline and click on the "Edit" button.

Step 2: Click on the "Triggers" tab to see the list of triggers configured for your pipeline.

Step 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.

Step 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.

Step 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:

Code to get Azure Devops Pipeline Trigger History

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.

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.

Streamline Workflow with Hatica

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 in 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
  • What is Azure Pipelines Trigger?
  • 7 Types of Azure Pipeline Triggers
  • 1. Scheduled Trigger
  • 2. Webhook Triggers
  • 3. Resource Triggers
  • 4. Continuous Integration (CI) Trigger
  • 5. Pull Request Trigger
  • 6. Code Change Trigger
  • 6. Manual Trigger
  • Configuring Pipeline Triggers
  • How to see the history of pipeline runs triggered by a specific trigger?
  • Common Azure Pipeline FAQs
  • Streamline Workflow with Hatica
  • TL;DR

Ready to dive in? Start your free trial today

Overview dashboard from Hatica