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:
- Navigate to your pipeline and click on the "Edit" button.
- Click on the "Triggers" tab to see the list of triggers configured for your pipeline.
- 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.
- 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.
- 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: