Blog Post

Apps on Azure Blog
2 MIN READ

Slot Swap with Preview

Prashant Pratap's avatar
Apr 01, 2019
First published on MSDN on Dec 12, 2016

Slot Swap with Preview enables us to run production specific app setting and database connection string in a slot website. This allows us to completely test the new deployment with actual production setting. Slot Swap with Preview also allows us to execute warm-up code so that website doesn't have any slow perf issues due to cold start.

There are three main phases in Slot Swap with Preview :

  1. Deploy new code to source slot website
  2. Apply Slot Config : Source slot website recycles and starts with destination slot specific settings (app setting and database connection string).
  3. At this time we can run our test and/or execute warm-up code using source slot website URL.
  4. Note: both destination and source slot website URLs will be running using destination slot specific settings
  5. Complete Slot Swap : if the test is successful, we can complete the swap. Now destination slot website URL will run source slot code with destination slot settings
  6. Reset Slot Swap : if the test fails, we can reset the swap. This will restart source slot website and run under source slot settings

We can do Slow Swap with Preview using Azure Portal as shown below. Note : select the right slot for source.

Here are PS cmdlets to execute Slot Swap with Preview

$AzureWebsiteName = "azinsights"

$AzureRGName = "InternalConsumptionResourceGroup"

$From = "test"

$To = "production"

#Switch-AzureWebsiteSlot -Name $AzureWebsiteName -Slot1 $From -Slot2 $To -Force -Verbose

Switch-AzureRmWebAppSlot -ResourceGroupName $AzureRGName -Name $AzureWebsiteName -SourceSlotName $From -DestinationSlotName $To -SwapWithPreviewAction ApplySlotConfig

Switch-AzureRmWebAppSlot -ResourceGroupName $AzureRGName -Name $AzureWebsiteName -SourceSlotName $From -DestinationSlotName $To -SwapWithPreviewAction CompleteSlotSwap

Switch-AzureRmWebAppSlot -ResourceGroupName $AzureRGName -Name $AzureWebsiteName -SourceSlotName $From -DestinationSlotName $To -SwapWithPreviewAction ResetSlotSwap

Before executing Apply Slot Config PS cmdlets, here are process ID and AppDomain ID of source and destination slot websites :

Production Slot

Test Slot

After executing Apply Slot Config PS Cmdlet, test slot website recycled and now using production database. Destination slot is untouched.

Production Slot

Test Slot

After executing Complete Slot Swap PS Cmdlet, production slot website has same process id as previous test slot website . And the new test slot website recycled and now using test database.

Production Slot

Test Slot

More Info

Azure Web App Deployment Slot Swap with Preview
Using PowerShell to manage Azure Web App Deployment Slots
Updated Aug 24, 2020
Version 2.0
No CommentsBe the first to comment