How to Deploy to App Service Slots and Swap in Azure Pipelines
Deploy to a staging slot, verify it, then use AzureAppServiceManage@0 to swap slots for a near-zero-downtime release.
Set deployToSlotOrASE: true and a slotName on AzureWebApp@1 to deploy to staging, then run AzureAppServiceManage@0 with action: Swap Slots.
Steps
- Create a
stagingdeployment slot on the App Service. - Deploy to the slot with
AzureWebApp@1anddeployToSlotOrASE: true. - Run smoke checks against the slot URL.
- Swap with
AzureAppServiceManage@0andaction: Swap Slots.
azure-pipelines.yml
azure-pipelines.yml
pool:
vmImage: ubuntu-latest
steps:
- task: AzureWebApp@1
inputs:
azureSubscription: 'my-azure-rm'
appName: 'my-web-app'
deployToSlotOrASE: true
resourceGroupName: 'prod-rg'
slotName: 'staging'
package: '$(Pipeline.Workspace)/drop/app.zip'
- task: AzureAppServiceManage@0
inputs:
azureSubscription: 'my-azure-rm'
action: 'Swap Slots'
WebAppName: 'my-web-app'
ResourceGroupName: 'prod-rg'
SourceSlot: 'staging'Gotchas
- Slot settings marked as deployment slot settings stay with the slot and do not swap.
- Warm the staging slot before swapping or the first production requests hit a cold start.
Related guides
How to Deploy a Web App With the AzureWebApp Task in Azure PipelinesDeploy a built package to Azure App Service from Azure Pipelines with the AzureWebApp@1 task, pointing it at…
How to Deploy Blue-Green With the Canary Strategy in Azure PipelinesRoll out a deployment gradually in Azure Pipelines with the canary strategy of a deployment job, using preDep…