Automating Azure Static Web Apps in Azure Pipelines
Azure Static Web Apps were launched earlier in 2021 and out of the box they had the capability to integrate your existing repository and deploy your Static Web App from Azure DevOps. You can reference the full getting started guide for the end-to-end deployment setup. Although, there is a caveat, the whole process is not entirely automated. When you create an Azure Static Web App you are required to copy the Deployment Token from the Azure portal into your variables in Azure DevOps.
While deployment using Azure DevOps is supported, we really want to be better automate our pipeline and take out the manual intervention of having to copy and paste our Deployment Token into our pipelines. The reality is, we are going to need to rotate our deployment token to maintain a highly secure application. Imagine if we were taking part in good security practices and rotated our tokens, but forgot that we had a manual step to update our pipeline variables? This would undoubtedly cause downtime in our Azure Static Web App.
In our pipeline we can create a task that runs a PowerShell script that pulls the latest Deployment token from the Azure portal, then updating our pipeline deployment token with the new token value. This automates what would have been a very manual process!
Here is a sample pipeline that includes this automation task:
Good luck and happy automating!
For more DevOps goodness have a look at the links below: