0
0
Azurecloud~5 mins

Deployment slots for staging in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Deployment slots let you create a separate place to test your app before making it live. This helps avoid problems by letting you check changes in a safe space.
When you want to test a new version of your web app without affecting users.
When you want to swap a tested version into production quickly.
When you want to reduce downtime during app updates.
When you want to roll back to a previous version easily if something goes wrong.
When you want to run different app settings for testing and production.
Commands
This command creates a new deployment slot named 'staging' for the web app 'example-app' in the resource group 'example-group'. It sets up a separate environment for testing.
Terminal
az webapp deployment slot create --resource-group example-group --name example-app --slot staging
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-group/providers/Microsoft.Web/sites/example-app/slots/staging", "name": "staging", "state": "Running", "type": "Microsoft.Web/sites/slots" }
--resource-group - Specifies the Azure resource group where the app is located
--name - Specifies the name of the web app
--slot - Names the deployment slot to create
This command lists all deployment slots for the web app 'example-app' to verify the 'staging' slot was created.
Terminal
az webapp deployment slot list --resource-group example-group --name example-app
Expected OutputExpected
[ { "name": "production", "state": "Running" }, { "name": "staging", "state": "Running" } ]
--resource-group - Specifies the resource group of the app
--name - Specifies the web app name
This command swaps the content and configuration of the 'staging' slot with the production slot, making the tested version live.
Terminal
az webapp deployment slot swap --resource-group example-group --name example-app --slot staging
Expected OutputExpected
Swapping slots... Swap completed successfully.
--resource-group - Specifies the resource group
--name - Specifies the web app name
--slot - Specifies the source slot to swap with production
This command deletes the 'staging' deployment slot when it is no longer needed to keep the environment clean.
Terminal
az webapp deployment slot delete --resource-group example-group --name example-app --slot staging
Expected OutputExpected
No output (command runs silently)
--resource-group - Specifies the resource group
--name - Specifies the web app name
--slot - Specifies the slot to delete
Key Concept

If you remember nothing else from this pattern, remember: deployment slots let you test app changes safely before making them live by swapping slots.

Common Mistakes
Trying to swap slots before deploying the app to the staging slot.
The staging slot will be empty or outdated, so swapping will not update the live app correctly.
Deploy your app to the staging slot first, test it, then run the swap command.
Deleting the production slot or confusing slot names.
Production slot cannot be deleted and mixing slot names can cause accidental downtime or data loss.
Always specify the correct slot name and never delete the production slot.
Not verifying slot creation before deployment.
If the slot does not exist, deployment commands will fail.
Use the slot list command to confirm the slot exists before deploying.
Summary
Create a staging deployment slot to test your app safely.
List slots to verify the staging slot exists.
Swap the staging slot with production to make tested changes live.
Delete the staging slot when it is no longer needed.