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.
2
Answers
Setting appsettings on a specific environment is not currently supported in the Azure Static Web apps CI/CD nor by the Azure CLI. There is a discussion in GitHub about it.
In
Azure Portal
, While Creating Static Web App, after providing theGitHub Repo
andBranch
details, we will get an option to preview the Workflow file.Yes, In Configuration Section we have an option to add the
App settings
. But it is a manual work, which is not advised to follow.Once we click on
Review + create
and create the Static Web App, a new folder with name.github/workflows
will be created in theGitHub Repository
.It contains the same workflow file (
preview file
), which we saw while creating theStatic WebApp
in Azure Portal.We can edit the Workflow manually.
To update the
appsettings/configurations
in the workflow, we can specify the steps in the existingworkflow
file.We can use either
Powershell/Azure CLI
commands to update theAppsettings
.***Sample code for Updating App settings: ***
Before
Build and deploy
step in Workflow, add the below steps.To edit the Workflow file, click on the
.github/workflow
=>.yml
fileReferences taken from MSDoc 1 and 2.
Update
As per the discussion in GitHub, adding appsettings to the preview environment is not currently supported in the default
Azure Static Web Apps CI/CD
.