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):

openhack-devops-proctor/polling.ps1 at master · Azure-Samples/openhack-devops-proctor · GitHub

openhack-devops-proctor/polling.sh at master · Azure-Samples/openhack-devops-proctor · GitHub

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.

In an Azure DevOps pipeline the stage would look like this:

Web app availability test

And then add a stage in the pipeline to swap the slot using a simple AZ CLI command, e.g.

Further to this you could also automate the traffic routing percentages, e.g:

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.

Useful links:

An experienced IT professional, focused on cloud tech and DevOps. Specialising in Azure, AWS, & Terraform. Currently working at BT Enterprise as a consultant.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store