Deploy pull request Artifacts with classic release pipelines

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

Pull requests provide an effective way to review code changes before merging them into the codebase. However, these changes can introduce issues that can be tricky to find without building and deploying the application to a specific environment. Pull request triggers enable you to define a set of criteria that must be met before deployment. This article explains how to set up pull request triggers with Azure Repos and GitHub repositories to deploy pipeline artifacts using Classic release pipelines.

Prerequisites

Product Requirements
Azure DevOps - An Azure DevOps project.
- Source code hosted on Azure Repos or GitHub. If you don’t have a repository, you can use the pipelines-dotnet-core sample app to create one.
- A working pipeline for your repository.
- A Classic release pipeline. If you don't have one, set up a Classic release pipeline.

Pull request deployments

Pull request triggers can help you maintain better code quality, release with higher confidence, and discover any issues early on in the development cycle.

Setting up pull request deployments is a two step process, first we must set up a pull request trigger and then set up branch policies (Azure Repos) or status checks (GitHub) for our release pipelines.

1. Enable pull request triggers

When pull request triggers are enabled, a new release is created whenever a new artifact becomes available in a pull request workflow:

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Pipelines > Releases and then select your release pipeline definition.

  3. In the Artifacts section, select the Continuous deployment trigger icon.

    A screenshot displaying how to access the continuous deployment trigger settings in Classic release pipelines.

  4. Toggle the Pull request trigger setting to enable it.

    A screenshot displaying how to enable pull request triggers in Classic release pipelines.

  5. Select your Target Branch from the dropdown menu.

    A screenshot displaying how to select your target branch.

  6. To deploy your application to a specific stage, explicitly opt in for that stage. The Stages section lists the stages enabled for pull request deployments.

    A screenshot displaying the list of stages that are enabled for pull request deployments.

    To enable pull request deployment for a stage:

    • Select the Pre-deployment conditions icon for the stage.
    • Navigate to Triggers > After release.
    • Toggle the Pull request deployment setting to enable it.

    A screenshot displaying how to enable pull request deployment for a specific stage.

Important

Enabling automatic pull request deployments for production stages is not recommended.

2. Set up branch policies

You can use branch policies to implement a list of criteria that must be met before a pull request can be merged.

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Repos > Branches to access the list of branches for your repository.

    A screenshot displaying how to navigate to branches in Azure Repos.

  3. Select the context menu for your appropriate branch ..., then select Branch policies.

    A screenshot displaying how to access branch policies for a specific branch.

  4. Select Add status policy, then select a Status to check from the dropdown menu. Select the status corresponding to your release definition and then select Save.

    A screenshot displaying how to add a status policy.

    Important

    The release definition must have run at least once with the pull request trigger enabled to see the list of statuses. See Configure a branch policy for an external service for more details.

  5. Once the status policy is added, users won't be able to merge changes to the target branch unless the pull request has a succeeded status.

    A screenshot displaying a list of status policies and the pull request deployment policy enabled.

  6. You can check the status of your policies on the pull request Overview page. Depending on your settings, the release status will be displayed under Required, Optional, or Status sections. The status updates each time the pipeline is triggered.

    A screenshot displaying the pull request policies status.