Azure DevOps pipelines are the backbone of modern software development, automating builds, tests, and deployments with ease.
You can trigger an Azure DevOps pipeline manually or automatically, depending on your needs.
Manual triggering is useful for one-off builds or deployments, while automatic triggering is perfect for continuous integration and delivery.
Automatic triggering is also known as continuous integration, where changes are automatically built and tested whenever code is pushed to the repository.
The trigger type determines how the pipeline is triggered, with options including continuous integration, scheduled, and external.
Pipeline Triggers
Pipeline Triggers are a powerful feature in Azure DevOps that enable you to automate your pipeline runs based on various events and triggers. There are several types of pipeline triggers, including Continuous Integration (CI), Pull Request Validation (PR), Scheduled Trigger, Webhook triggers, Repo triggers, Branch Filters, Tag Filters, and Stage Filters.
You can configure pipeline triggers in Azure Pipelines by navigating to your pipeline and clicking on the "Edit" button, then selecting the "Triggers" tab. From there, you can choose 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.
Here are some key things to keep in mind when working with pipeline triggers:
- You can view the history of pipeline runs triggered by a specific trigger by clicking on the trigger in the "Triggers" tab and looking at the "Recent runs" section.
- You can filter the list of runs by status, date range, and other criteria to help you find the specific runs you're interested in.
- Webhook triggers allow you to automatically trigger pipeline runs based on external events, such as changes to a GitHub repository or a new Docker image being pushed to a container registry.
- Repo triggers can be controlled with simple syntax, allowing you to specify branches and paths to include and exclude.
- Branch Filters allow you to trigger the build only when specified criteria are matched, such as including or excluding specific branches.
- Tag Filters allow you to specify which pipeline creation events can trigger your pipeline, based on tags.
- Stage Filters allow Azure Pipeline to trigger another pipeline when one or more stages of the Triggering Pipeline are complete.
Webhook
Webhook triggers in Azure Pipelines allow you to automatically trigger pipeline runs based on external events. You can create a webhook in the external service to notify Azure Pipelines when the event occurs, and then configure the webhook trigger to start a pipeline run based on the webhook's configuration.
To use webhook triggers, you need to define a webhook event based on any HTTP event, such as a repository commit, PR remark, registry update, or a simple HTTP post request. You can then specify the payload URL to receive the event and configure the webhook trigger to start a pipeline run.
Webhook triggers are slightly different from other resource-based triggers, as there is no downloadable artifact component or version associated with each event. However, webhook events contain JSON payload data that can be used for basic analysis of the event.
Here's a summary of the webhook trigger options:
- I would like to configure my pipeline to trigger based on an external event.
- I would like to apply some additional filters on the payload I get from external event and trigger my pipeline.
- As part of the triggered pipeline, I would like to consume the JSON payload available as part of the event in my jobs.
You can establish a webhook event based on any HTTP event and provide the destination to receive the event via the payload URL. Your webhook triggers can be initiated by a repository commit, PR remark, registry update, or a simple HTTP post request.
For example, you can use webhook triggers to automate your pipeline and streamline your software development process by triggering 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.
Manual
The Manual trigger allows you to start a pipeline run by hand. This can be super useful for one-time deployments or other situations where you need to run a pipeline outside of its normal schedule.
You can use the Manual trigger to run a pipeline manually, such as deploying a new release to production.
Scheduled
Scheduled triggers allow you to run a pipeline on a schedule, such as every day at 6:00 am or every week on Fridays at 9:00 pm.
You can set a specific time and frequency for the trigger to run, making it perfect for tasks like nightly backups.
To define and run scheduled triggers, you can use the Pipeline Settings UI or configure it using a CRON syntax. Most users find the UI option simpler.
If you schedule your triggers using both the UI settings and the CRON syntax, the UI settings will be given precedence over the syntax. So, be sure to remove any scheduled triggers defined in your Pipeline Settings UI if you're using CRON.
You can view your upcoming scheduled runs for a specific pipeline by visiting the Kebab Menu and clicking the option "Scheduled runs". You can also check your completed scheduled triggers from the option Trigger Runs > Schedule.
Scheduled triggers are helpful for cases when you want to run long-running builds or repeated tasks on a schedule, such as active automated penetration tests or database exports/imports from prod to earlier environments.
In contrast to CI & PR triggers, scheduled triggers don't have default schedules, and you need to explicitly specify an include-branch for them to work. Just specifying excludes does nothing, but you could do includes: * first.
Azure DevOps goes to sleep five minutes after the last user logs out, which can cause scheduled triggers to not run as expected. However, after a user logs in, your scheduled pipelines will still run once, but CI triggers from GitHub/BitBucket will stop working.
Trigger Types
Azure Pipelines supports several types of pipeline triggers, each designed to handle different scenarios.
You can use up to 7 different types of Azure Pipeline Triggers.
These triggers cannot use variables for anything due to the way they are evaluated in a pipeline.
All of the triggers mentioned can also be overridden in the portal to use the old GUI based logic for setting them up.
It's generally better to have all of the possible pipeline logic visible in the YAML file, so it's recommended to avoid using the old GUI based logic.
Note that triggers often have a full syntax and a short one, and you may not need to specify everything that's listed.
Trigger Evaluation
Trigger Evaluation is a crucial aspect of Azure DevOps pipeline triggers. It determines which branch of the self-repo to pick the YAML definition from based on the trigger defined on each resource.
If the pipeline resource is from the same repo as the current pipeline, the branch of the self-repo will be followed based on the pipeline resource event. For example, if an Azure pipeline 'SmartHotel.CI' from 'SmartHotelsRepo' is added as a pipeline resource for another Azure pipeline 'SmartHotel.CD', a new pipeline run will be triggered for 'SmartHotel.CD' by picking the YAML from the 'releases/M145' branch.
For all other resources, such as repository or container, or if the pipeline resource is from a different repo, the pipeline run will be triggered from the default branch of the pipeline, which is the same as the default branch of the repo. This is illustrated by the example of adding 'HelmRepo' as a repository resource to the current pipeline 'SmartHotel.CD', which runs on 'SmartHotelsRepo'.
Pipeline Configuration
To configure pipeline triggers in Azure Pipelines, navigate to your pipeline and click on the "Edit" button, then select the "Triggers" tab.
From there, you can select the trigger type and configure the trigger settings, such as choosing the branch(es) for a Continuous Integration trigger.
To see upcoming scheduled runs, access the Kebab Menu and click on "Scheduled runs", while completed Scheduled Triggers can be viewed by selecting "Trigger Runs" and then "Schedule".
Azure Filters
Azure Filters are a powerful tool in Azure Pipelines that allow you to control which pipeline runs get triggered.
You can use Branch Filters to specify which branches to include or exclude when setting up the Azure Pipeline Trigger. This is done by defining the branch specification, which can include wildcard characters like "features/modules/*".
Branch Filters are triggered by the successful finish of a Source Pipeline run that matches the specified criteria. This means that if a pipeline run meets the branch filter conditions, a new pipeline will be started.
Tag Filters, on the other hand, allow you to specify pipeline creation events that can trigger your pipeline. If the triggering pipeline matches all of the tags in your tags list, the pipeline gets executed.
Tags serve as metadata to help you sort, organize, and find records in Azure DevOps. They are critical for pipeline configuration and can be used to filter pipeline creation events.
Configuring Pipeline
To configure pipeline triggers, navigate to your pipeline and click on the "Edit" button, then click on the "Triggers" tab to see the available trigger options.
Selecting the trigger type is a crucial step, and you can choose from various options such as Continuous Integration or pull requests.
To configure a CI trigger, select the "Continuous Integration" option and choose the branch(es) you want the trigger to run on.
You can also view upcoming scheduled runs for a particular pipeline by accessing the Kebab Menu and clicking on the "Scheduled runs" option.
This feature allows you to plan and manage your pipeline runs in advance, ensuring that everything runs smoothly and on time.
To see completed Scheduled Triggers, select the "Trigger Runs" option and then click on "Schedule".
CI and CD
Continuous Integration (CI) is a crucial aspect of Azure DevOps pipeline triggers. It automatically builds and tests 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, making it a flexible tool for developers. This ensures that your code is always in a deployable state.
Azure DevOps offers a CI trigger, which is the most common type of trigger. It's used to run your build and tests automatically every time code changes are pushed to the repository.
Continuous Integration (CI)
Continuous Integration (CI) is a game-changer for automating your build and testing process. You can trigger a pipeline with just a push to the repo, and it'll get your code built and packaged ready for release.
By default, pipelines run on each push on all branches, but you can specify triggers for specific branches or tags. For example, you can include certain branches or file paths under "include:" and exclude others under "exclude:".
You can also configure triggers based on refs/tags, giving you more control over which branches get triggered. If you want to disable CI triggers altogether, simply add "trigger: none" to your file.
If you have multiple pushes happening at the same time, you can batch runs with "batch: true", resulting in a single build for all changes. This is false by default, so you'll get a new build for each push.
You can also skip CI triggers for a push by including "[skip ci]" in your commit message or description. This is a handy feature for when you don't want to trigger a build.
Continuous Deployment (CD)
Continuous Deployment (CD) is a software development practice where new changes are automatically deployed to production after passing a series of automated tests.
The goal of CD is to reduce the time and effort required to get new features and bug fixes in front of customers. This is achieved by automating the deployment process, which allows teams to release software updates more frequently.
Automated testing is a key component of CD, as it ensures that new code changes don't break existing functionality. According to our earlier discussion, automated testing can catch up to 90% of bugs, reducing the likelihood of errors in production.
By automating the deployment process, teams can deploy new software updates multiple times a day, rather than waiting for a large batch of changes to be released all at once. This allows teams to respond quickly to changing customer needs and stay ahead of the competition.
Continuous Deployment is often paired with Continuous Integration (CI), which ensures that code changes are regularly integrated into a central repository. By combining CI and CD, teams can achieve a seamless development process that reduces the risk of errors and increases the speed of delivery.
Sources
- https://github.com/microsoft/azure-pipelines-yaml/blob/master/design/pipeline-triggers.md
- https://hevodata.com/learn/azure-pipeline-triggers/
- https://www.hatica.io/blog/azure-pipeline-triggers/
- https://www.huuhka.net/azure-pipelines-yaml-trigger-overview/
- https://keda.sh/docs/2.15/scalers/azure-pipelines/
Featured Images: pexels.com