How can I automatically select Blue or Green for Blue/Green deployments using Octopus Deploy?

Both the blue and green versions of my web application are on the same VM. I use an F5 load balancer which points to either the blue version or the green version. My deployment looks like this (assume Blue is active):

  1. Deploy database
  2. Deploy to Green web application
  3. Update F5 to point to Green version of the application

Right now I have to have two environments, one blue and one green. I’d like to have a single environment. How can I have a single environment, Production while still having blue/green deployments? I could look at the previous deployment and determine which one, blue or green, was last deployed to.

In this case I’d recommend calculating that at the start of the deployment. I’d query the load balancer/f5/whatever and determine which site, blue or green, is active. I wouldn’t look at a previous deployment in Octopus as that isn’t the truth center of what is currently active. You could’ve manually changed it outside of octopus.

Once you know which is active, you can set that value as an output variable: https://octopus.com/docs/deployment-process/variables/output-variables.

Subsequent steps and variables can then leverage that output variable to determine. What I like to do with output variables is put them in another variable to make it easier to access :slight_smile:

image

So your process would look something like this:

  1. Script to calculate blue or green -> set output variable
  2. Deploy database
  3. Using output variable, deploy to blue folder or green folder in IIS
  4. Script to swap to blue or green