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: