Using Deployment Slots with Azure Web Apps

Last updated

Deployment Slots provide a nice way to implement Blue-Green deployments for Azure Web Apps.

This provides many benefits, including:

  • Reduced down-time when deploying.
  • When deploying packages with a large number of files, deployment times can be significantly reduced due to not having to compare with existing files (this assumes you are deploying to a clean slot).
  • Roll-back can be achieved by simply swapping the slots back.

Deployment Slots are only available to Azure Web Apps running in Standard or Premium App Service plans


Here we will give an example of how to setup a Blue-Green deployment for an Azure Web App using Deployment Slots.

Step 1: Create Staging Slot

Create a Run an Azure PowerShell Script step.

Assuming you have a variable named 'WebSite' that contains the name of your Azure Web Site, your script should be:

Azure Service Management

#Remove the staging slot if it exists
Remove-AzureWebsite -Name #{WebSite} -Slot Staging -Force

#Create the staging slot
New-AzureWebsite -Name #{WebSite} -Slot Staging

Azure Resource Manager

#Remove the staging slot if it exists
Remove-AzureRMWebAppSlot -Name #{WebSite} -Slot Staging -ResourceGroupName MyResourceGroup -Force -ErrorAction Continue

#Create the staging slot
New-AzureRMWebAppSlot -Name #{WebSite} -Slot Staging -ResourceGroupName MyResourceGroup

The reason for the first line, which removes the Staging Slot, is to ensure we are deploying to a clean slot.  This can significantly reduce the time taken for deployments with a large number of files.

So your step should look like:

Step 2: Deploy your Package

The next step is to deploy your package to the Staging slot.  We do this by creating a Deploy an Azure Web App step.

Slots in Azure are themselves real Web Apps with their own hostnames.  They are named with the format:


If your Staging Slot already exists, you can see it in the select-list of available sites for your account.

To use a variable for the WebSite name, click the "Bind" Bind button, and enter


As shown below:

Step 3: Swap the Staging and Production Slots

The final step is to create another Azure PowerShell step to swap the Staging and Production slots.

Use the PowerShell:

Azure Service Management

#Swap the staging slot into production
Switch-AzureWebsiteSlot -Name #{WebSite} -Slot1 Staging -Slot2 Production -Force

Azure Resource Management

#Swap the staging slot into production
Switch-AzureRmWebAppSlot -ResourceGroupName #{ResourceGroup} -Name #{Website} -SourceSlotName Staging -DestinationSlotName Production

So your step will appear as:

At this point you should have a working Blue-Green deployment process for your Azure Web App.