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
In your Azure DevOps project, go to Pipelines > Releases.
Click "New pipeline" to create a new release pipeline.
Select "Azure App Service deployment" as the template or start with an empty job.
Rename the default stage to "Dev Deployment".
2. Configuring the Artifact
In the pipeline view, click "Add an artifact".
Select "Azure Pipelines" as the source type.
Choose your project and the specific build pipeline.
Keep the default version as "Latest" or select a specific version if needed.
Click "Add" to add the artifact.
Enable the continuous deployment trigger by clicking the thunder icon on the artifact.
Select the branch that should trigger the deployment (e.g., the default branch).
3. Setting Up the Dev Deployment Stage
Click on the "1 job, 1 task" link in the Dev Deployment stage.
In the "Agent job" section, select the appropriate agent pool (e.g., Azure Pipelines with ubuntu-latest).
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
Click on the "Pre-deployment conditions" for the Dev Deployment stage.
Enable "Gates" and click "Add" to add a gate.
Select "Query Work Items" as the gate type.
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)
(Optional) Add more gates as needed (e.g., Invoke REST API, Azure Monitor, etc.)
5. Creating the Production Deployment Stage
Clone the Dev Deployment stage.
Rename the cloned stage to "Prod Deployment".
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
In the deployment task, uncheck "Deploy to Slot or App Service Environment" to deploy to the production slot.
6. Configuring Deployment Slots
In the Azure portal, go to your App Service.
Under "Deployment" in the left menu, click "Deployment slots".
Click "Add Slot" and name it "staging".
Clone settings from the production slot if desired.
Back in the Azure DevOps release pipeline, edit the Dev Deployment stage.
In the "Deploy Azure App Service" task, check "Deploy to Slot or App Service Environment".
Select the "staging" slot you just created.
7. Running the Pipeline
Make sure your build pipeline is configured to publish artifacts without deploying.
Commit and push changes to your repository to trigger the build pipeline.
Once the build is complete, it should automatically trigger the release pipeline.
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
After successful deployment to both staging and production slots:
In the Azure portal, go to your App Service.
Click on "Deployment slots" in the left menu.
Click the "Swap" button at the top.
Confirm the source and target slots for the swap.
(Optional) Choose "Perform swap with preview" for a phased swap.
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.