Recently, I wanted to restart an Azure App Service (multiple instances) in an Azure DevOps YAML pipeline after applying the Infrastructure as Code (IaC) config to ensure the latest Azure Key Vault secrets are loaded by the app. This is required if the secret rotation is performed on each deployment with IaC.
To preserve the knowledge, I decided to write this really short blog post about it.
Restarting an Azure App Service in an Azure DevOps YAML pipeline can be implemented as follows.
- task: AzureCLI@2
displayName: Restart Azure Web App (App Service)
inputs:
azureSubscription: AZURE_SUBSCRIPTION_NAME
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az webapp restart --name AZURE_APP_SERVICE_NAME --resource-group RESOURCE_GROUP_NAME
RESOURCE_GROUP_NAME is the name of the resource group that contains the Azure App Service to be restarted.
For more details about secret rotation see the following blog post.
[HOWTO] Rotate Azure Key Vault secrets used by an ASP.NET Core Web API with Terraform on every deployment
The blog post details the process of rotating secrets stored in Azure Key Vault with each application deployment, utilizing Infrastructure as Code (IaC) principles via Terraform. It emphasizes the importance of secret rotation to minimize risks from leaks. An ASP.NET Core Web API is demonstrated as the application example, alongside procedural GitHub Actions for deployment.

I’m doing something similar. But I found the AzureAppServiceManage task easier to use. So, here’s to inspiration if someone prefer not knowing the Azure CLI:
– task: AzureAppServiceManage@0
inputs:
azureSubscription: AZURE_SUBSCRIPTION_NAME
Action: ‘Restart Azure App Service’
WebAppName: AZURE_APP_SERVICE_NAME
LikeLiked by 1 person
Interesting. Looks indeed simpler. Thanks a lot for sharing!
LikeLike