Blue-green deployments with Octopus Deploy and Azure deployment slots

December 5, 2017 | by Rodolfo Ortiz

In Azure, App development, developers

In a software project, you should continuously perform process improvement. In the project I'm working on, we recently implemented blue-green deployments in our QA environment.

Blue-green deployments are a way to reduce the amount of time an environment is not reachable during a deployment. This is achieved by having 2 environments ("blue" and "green").


During the project, you usually have one or more live environment, which we'll call "blue". By environment I mean the QC environment, the UAT environment or even the production environment. Then, every now and then, you perform deployments in one of these environments. In blue-green deployments, when you perform a deployment, it’s done in an alternate environment, which we'll call "green" -as you can see, this is different from regular deployments in which you always deploy in the same environment-. The green environment should have the same configuration and settings of the blue environment. Once the application is deployed in the green environment, you swap the environments so that the requests now go to the green environment and then the blue environment is removed from service.


A powerful reason to use blue-geen environmentsThe main advantage is reduced downtime during deployments. Let's focus on the QA environment for now, which is where we implemented blue-green deployments. In our project we used to let the team know every time we performed a deployment in our QA environment since the environment would be unreachable while the deployment was performed. After implementing blue-green deployments, we didn't have the need to communicate the deployment to the team since the environment would always be reachable.


 Of course, you need extra hardware to achieve blue-green deployments; however, we implemented it with Azure deployment slots, which made the setup straight-forward. Also, we use Octopus Deploy to perform the deployments.

The general steps are these assuming you already have a process to deploy your application in Azure, and you only need to enable the blue-green deployment. You need to set it up in Octopus Deploy:

  1. First, you need to create a Service Principal in Octopus Deploy. For more information on how to do this, click here
  2. Then, add a step in Octopus Deploy to create the staging slot in Azure through a PowerShell script -this is the green environment-. It should be done before you deploy your package.
  3. Change the step in which you deploy your package so that it points to the staging slot when doing the deployment. This means that from now on you’ll deploy in the staging slot.
  4. After your package is deployed, add a new PowerShell script step to swap the staging and production slots. Make sure you don't confuse the production slot with the production environment. They are different things. Here, we’re referring to the production slot.
  5. Finally, add a step to remove the staging slot.

For more information on deployment slots you can click here.

For a thorough explanation from Octopus Deploy please refer to this article.