Search code examples
azureappsettingsazure-static-web-app

How to configure appsettings on a auto-generated preview environment


How can I change the appsettings on the preview environemnts that are generated by the Azure Static Web Apps CI/CD Github Action for each pull request?

I can go to the portal, navigate to the generated environment and change its appsettings. Doing this manually for each new pull request is error prone and will become tedious really fast.

I couldn't find any reference to this in the Build Configuration For Azure Static Webapps docs so I'm assuming it can't be configured that way. I also couldn't find any reference to SWA environments in the CLI docs. I looked into deployment environments but it looks like this is some other kind of deployment environment as it keeps mentioning devcenter.


Solution

  • Since April 2023 and CLI Version 2.48. this is now possible. You can set environment specific variables via the CLI

    // First collect the preview env name via -> result[x].name
    az staticwebapp environment list -n swa-resource-name-xyz
    
    // Then use the name to set the env vars
    az staticwebapp appsettings set --name swa-resource-name-xyz --environment-name looked-that-up --setting-names CUSTOM_ENV_VAR=Different_On_Feature_Branch
    

    Indeed, I miss that the Azure Portal has this option as well. It's a bit hidden on the "Environment Variables" section at the top of the page. There is a dropdown where you can select the environment.