Azure DevOps Release Pipeline Guide: From Setup to Blue-Green Deployment

Azure DevOps Release Pipeline Guide: From Setup to Blue-Green Deployment

In this comprehensive guide, we'll walk through the process of setting up an Azure DevOps release pipeline, implementing continuous deployment, and utilizing deployment slots for blue-green deployment. We'll be using a YouTube clone project as our example.

Table of Contents

  1. Creating the Release Pipeline

  2. Configuring the Artifact

  3. Setting Up the Dev Deployment Stage

  4. Adding Deployment Gates

  5. Creating the Production Deployment Stage

  6. Configuring Deployment Slots

  7. Running the Pipeline

  8. Implementing Blue-Green Deployment

1. Creating the Release Pipeline

  1. In your Azure DevOps project, go to Pipelines > Releases.

  2. Click "New pipeline" to create a new release pipeline.

  3. Select "Azure App Service deployment" as the template or start with an empty job.

  4. Rename the default stage to "Dev Deployment".

2. Configuring the Artifact

  1. In the pipeline view, click "Add an artifact".

  2. Select "Azure Pipelines" as the source type.

  3. Choose your project and the specific build pipeline.

  4. Keep the default version as "Latest" or select a specific version if needed.

  5. Click "Add" to add the artifact.

  6. Enable the continuous deployment trigger by clicking the thunder icon on the artifact.

  7. Select the branch that should trigger the deployment (e.g., the default branch).

3. Setting Up the Dev Deployment Stage

  1. Click on the "1 job, 1 task" link in the Dev Deployment stage.

  2. In the "Agent job" section, select the appropriate agent pool (e.g., Azure Pipelines with ubuntu-latest).

  3. In the "Deploy Azure App Service" task:

    • Select your Azure subscription

    • Choose "Web App on Linux" as the app type

    • Select your App Service name

    • Leave the Startup Command blank

4. Adding Deployment Gates

  1. Click on the "Pre-deployment conditions" for the Dev Deployment stage.

  2. Enable "Gates" and click "Add" to add a gate.

  3. Select "Query Work Items" as the gate type.

  4. Configure the gate:

    • Select the appropriate query (e.g., P1 tasks)

    • Set the upper threshold (e.g., 2)

    • Set the lower threshold (e.g., 0)

  5. (Optional) Add more gates as needed (e.g., Invoke REST API, Azure Monitor, etc.)

5. Creating the Production Deployment Stage

  1. Clone the Dev Deployment stage.

  2. Rename the cloned stage to "Prod Deployment".

  3. Configure pre-deployment conditions:

    • Set the trigger to "After release"

    • Add a pre-deployment approval:

      • Add approvers (e.g., yourself or team leads)

      • Set the approval timeout

      • Configure any additional options as needed

  4. In the deployment task, uncheck "Deploy to Slot or App Service Environment" to deploy to the production slot.

6. Configuring Deployment Slots

  1. In the Azure portal, go to your App Service.

  2. Under "Deployment" in the left menu, click "Deployment slots".

  3. Click "Add Slot" and name it "staging".

  4. Clone settings from the production slot if desired.

  5. Back in the Azure DevOps release pipeline, edit the Dev Deployment stage.

  6. In the "Deploy Azure App Service" task, check "Deploy to Slot or App Service Environment".

  7. Select the "staging" slot you just created.

7. Running the Pipeline

  1. Make sure your build pipeline is configured to publish artifacts without deploying.

  2. Commit and push changes to your repository to trigger the build pipeline.

  3. Once the build is complete, it should automatically trigger the release pipeline.

  4. Monitor the release pipeline progress:

    • Check that the artifact is successfully linked

    • Verify that the deployment gates are evaluated correctly

    • Ensure the Dev Deployment (staging slot) completes successfully

    • Approve the Production Deployment when prompted

    • Confirm the Production Deployment completes successfully

8. Implementing Blue-Green Deployment

  1. After successful deployment to both staging and production slots:

  2. In the Azure portal, go to your App Service.

  3. Click on "Deployment slots" in the left menu.

  4. Click the "Swap" button at the top.

  5. Confirm the source and target slots for the swap.

  6. (Optional) Choose "Perform swap with preview" for a phased swap.

  7. Click "Swap" to perform the blue-green deployment.

By following these steps, you've successfully set up a release pipeline in Azure DevOps with continuous deployment, deployment gates, and blue-green deployment using deployment slots. This setup allows for safer, more controlled releases with minimal downtime.

Remember to always test your pipeline thoroughly and adjust the configuration to meet your specific project requirements.