Deploying to Azure Static Web Apps in Azure DevOps

I have started moving several static websites & SPAs from “Static website hosting in Azure Storage” to Azure Static Web Apps (SWA). Main reason for this is the limitation of using apex domains with Azure CDN which is the only way to use custom domains on websites hosted with Azure Storage. This is not an issue with Static Websites where you can use ALIAS, CNAME or A Records to map your domains. And with two custom domains available in the free tier this is now my go-to default.

One thing I dont really like about SWAs is that deployments work very differently to similar resources like web apps or function apps. I’d love to just copy my static files using az cli. Instead I need to have a deployment token and use for example the specialized swa cli. Many docs and posts suggest to store the deployment token in the KeyVault or pipeline secrets, but I prefer to retreive it during the pipeline execution as the service principal has the required permissions anyway.

So here’s what it looks like to simply deploy a folder with static html in Azure DevOps pipelines:

- task: AzureCLI@2
  displayName: 'Deploy to SWA'
  inputs:
    azureSubscription: 'MyServicePrincipal'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      deploymentToken=$(az staticwebapp secrets list --name "$(STATIC_WEB_APP_NAME)" --query "properties.apiKey" -o tsv)

      swa deploy '$(Pipeline.Workspace)/$(artifactName)' --deployment-token $deploymentToken --env 'production'




Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.