
Azure DevOps triggers are a crucial part of automating workflows, allowing you to run pipelines on specific events.
Triggers can be set up to run on a variety of events, including code check-ins, pull requests, and build completions.
There are several types of triggers available, each serving a unique purpose.
Let's dive into the different types of triggers and how they can be used to streamline your development process.
Readers also liked: Azure Function Triggers
Azure DevOps Triggers
Azure DevOps Triggers are an essential part of automating your workflow. There are three types of Triggers that can be defined at the Pipeline-level: CI Triggers, PR Triggers, and Scheduled Triggers.
CI Triggers are not explicitly mentioned in the provided article sections, but we can infer that they are one of the three types of Triggers. PR Triggers, on the other hand, trigger on pull requests to the Pipeline's repo.
Scheduled Triggers are optional and can be defined in two different places: in your YAML Pipeline or in the Azure DevOps UI. If you define schedules in both places, the ones in the Azure DevOps UI will be the only ones that run.
If this caught your attention, see: Azure Devops Pull Request Checks
You can define Scheduled Triggers to run your Pipeline at a specific schedule. The three Trigger options that can be used at the root of your Pipeline are: Trigger on updates to the Pipeline's repo, Trigger on pull requests to the Pipeline's repo, and Trigger on a schedule.
Here's a summary of the three Trigger options:
- Trigger on updates to the Pipeline's repo
- Trigger on pull requests to the Pipeline's repo
- Trigger on a schedule
Implementing Triggers
You can disable CI triggers by setting the trigger to "none". This will prevent any automatic runs of your pipeline.
The full syntax for complete control over triggers is trigger: batch, branches, paths. However, it's worth noting that batch is not supported in repository resource triggers.
To configure pipeline resource triggers, you can use the trigger: enabled, branches, stages, tags syntax.
If you want to specify none to disable triggers, you can use the trigger: none syntax. Alternatively, you can use trigger: true to include all branches.
Here's a summary of the trigger syntax:
By using the correct trigger syntax, you can customize your pipeline to run automatically on specific branches, stages, or tags.
Pipeline Configuration
Pipeline configuration is crucial to set up your Azure DevOps triggers effectively. You can configure your builds with a CI trigger on all branches by default, as mentioned in Step 4.
To control which branch gets triggered, you'll need to include the branches you want to trigger and then exclude the branches you don't want to trigger, as explained in Step 5. This allows you to customize your pipeline configuration to suit your project's needs.
CI triggers vary based on the type of repository you build in your pipeline, including Azure Repos Git, GitHub, Bitbucket Cloud, and TFVC. You can also use pipeline triggers in YAML pipelines and build completion triggers in classic build pipelines to trigger one pipeline upon the completion of another.
Here's a summary of the different types of CI triggers:
- CI triggers in Azure Repos Git
- CI triggers in GitHub
- CI triggers in Bitbucket Cloud
- CI triggers in TFVC
Properties
In a pipeline configuration, properties play a crucial role in determining how and when a pipeline runs.
The "enabled" property is a boolean that determines whether the trigger is enabled, with a default value of true.
Curious to learn more? Check out: Azure Devops Pipeline Triggers
You can include or exclude specific branch names for triggering a run using the "branches" property, which allows you to specify branch names to include or exclude.
File paths can also be included or excluded for triggering a run using the "paths" property, which uses include and exclude filters to determine which files to consider.
Tags can be used to trigger a pipeline, and the "tags" property allows you to specify a list of tags that will trigger the pipeline when matched.
Discover more: Azure Devops Branch Policies
Step 5
To configure builds, you need to specify the branches that will trigger the pipeline. This is done by including the branches you want to trigger.
You can include multiple branches by listing them, separated by commas. For example, you can include both the main branch and a feature branch by specifying "main, feature/new-feature".
To exclude branches, you simply need to list them as well. This will prevent the pipeline from triggering on those branches.
See what others are reading: Azure Devops Deleted Branches
Build Pipelines
Build Pipelines are a crucial part of any development workflow, allowing you to automate builds and deployments. They can be triggered by various events, including continuous integration (CI) and pull request validation (PR) triggers.
There are different types of CI triggers, depending on the type of repository you're working with. For Azure Repos Git, GitHub, Bitbucket Cloud, and Team Foundation Version Control (TFVC), the CI triggers vary accordingly. Similarly, PR triggers also differ based on the repository type.
To illustrate the difference, consider this: if you're working with Azure Repos Git, you'll need to configure CI triggers differently than if you were using GitHub. The same goes for PR triggers.
Here's a quick rundown of the different CI and PR triggers:
- CI triggers in Azure Repos Git
- CI triggers in GitHub
- CI triggers in Bitbucket Cloud
- CI trigger YAML schema reference
- PR triggers in Azure Repos Git
- PR triggers in GitHub
- PR triggers in Bitbucket Cloud
- PR trigger YAML schema reference
Pipeline triggers in YAML pipelines and build completion triggers in classic build pipelines allow you to trigger one pipeline upon the completion of another. This can be a powerful way to automate your workflow and ensure that builds are completed in the right order.
Consider reading: Azure Devops Trigger Yaml
Trigger Types
There are three main types of triggers in Azure DevOps: CI, PR, and Scheduled Triggers.
CI Triggers are designed to kick off a pipeline when code changes are made and a Continuous Integration build is required.
PR Triggers can be defined at the pipeline level to automatically trigger a build when a pull request is created or updated.
Scheduled Triggers allow you to schedule a pipeline to run at a specific time or frequency, giving you more control over when your builds and deployments occur.
Worth a look: Azure Devops Trigger Build after Pull Request
Trigger: String List
A string list trigger is a type of trigger that uses a list of strings to define a condition.
This trigger is useful for checking if a specific value is in a list of allowed values. For example, in the "String List Trigger" section, we saw how to create a trigger that checks if a user's role is in a list of authorized roles.
The list of strings can be static or dynamic, meaning it can be predefined or generated at runtime. A static list is defined at the time the trigger is created, while a dynamic list is generated based on some criteria or data.
Scheduled Triggers
Scheduled Triggers are optional, meaning you don't have to use them if you don't want to. If you omit the schedules: parameter, your Pipeline won't run on a schedule.
Schedules can be defined in two places: in your YAML Pipeline or in the Azure DevOps UI. If you define schedules in both places, the ones in the Azure DevOps UI will be the only ones that run.
Here are the three Trigger options that can be used at the root of your Pipeline:
- Trigger on updates to the Pipeline's repo
- Trigger on pull requests to the Pipeline's repo
- Trigger on a schedule
Scheduled Triggers are defined in the same place as the other Trigger options, which is at the root of your Pipeline.
Continuous Integration
Continuous Integration is a powerful feature in Azure DevOps that allows you to automate the build and testing of your code whenever changes are made to your repository.
To enable CI in your Azure DevOps project, navigate to the "Pipelines" screen and click on the "More Options" button on the right of your specific pipeline, then click "Edit".
You can define CI Triggers in your Pipeline's YAML file to automatically kick off a run of your Pipeline when updates are made to your repository.
CI Triggers are optional, but if you omit the trigger: parameter, any update to any branch of your repository will cause your Pipeline to trigger, which may not be desirable behavior.
There are three possible options for defining CI Triggers: setting the batch: parameter to true, specifying either branches: or tags:, or both.
If you specify both branches: and tags:, both will be considered, and if at least one of them matches, the pipeline will be triggered.
The paths: parameter cannot be used by itself and can only be used in combination with the branches: parameter, and paths in Git are case-sensitive.
On a similar theme: Azure Devops Compare Branches
Featured Images: pexels.com


