Using Azure webapp slots with CI/CD pipelines — Blue-Green Deployments & A/B testing.
Azure web apps have the concept of slots. These are effectively a copy of the web app with a unique DNS name, which you can deploy your updated app to for testing, before swapping the slots to make the copy the master. The slots are commonly referred to as ‘staging’ and ‘production’.
This is known as a ‘blue-green’ deployment. The swap is done in a big bang approach, and minimises any downtime.
‘A/B testing’ introduces the concept of directing a percentage of the traffic to staging, and a percentage to production for testing new application features. For example, you might be concerned with the customer conversion rate of your new feature, would it improve conversion rates or reduce them?
A/B testing allows you to analyse this, testing the new feature with say 10% of the traffic, then increasing the percentage traffic to slowly introduce the change into production, eventually directing 100% to the new app if successful.
In Azure web apps, the swap process can be automated using CI/CD pipelines. When an app is deployed to staging, a test could be introduced into the pipeline to first test the staging web app availability, and if successful, swap a portion of the traffic to the staging slot.
You can find Powershell and bash scripts to check web app availability on Github (change the http response as required):
To add this test to a CI/CD pipeline, add a Azure CLI stage and add the code as an inline script, with the -i argument specifying the URI of the website.
Or you can simply run a curl command and grep for the expected response, e.g.
curl -i https://www.website.com | grep -i "healthy"
In an Azure DevOps pipeline the stage would look like this:
And then add a stage in the pipeline to swap the slot using a simple AZ CLI command, e.g.
az webapp deployment slot swap -g test1 -n test2 — slot staging \
— target-slot production
Further to this you could also automate the traffic routing percentages, e.g:
az webapp traffic-routing clear — name test1— resource-group test2az webapp traffic-routing show — name test1 — resource-group test2
In terms of testing and monitoring the staging slot, and ultimately approving it for production, another tool you could use would be Azure monitor to check the status of the web app, and swap back automatically if an error status was detected.
Azure Slot Deployment with Blue-Green Deployment Model
In this article, we will learn how to use Blue-Green deployment model for continuous delivery pattern.
Blue-green Deployments, A/B Testing, and Canary Releases
A lot of teams I talk to recently are very interested in "DevOps" (whatever that means... seems to mean different…