skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. In Azure Portal, While Creating Static Web App, after providing the GitHub Repo and Branch details, we will get an option to preview the Workflow file.

    enter image description here

    I can go to the portal, navigate to the generated environment and change its appsettings

    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.

    enter image description here

    Once we click on Review + create and create the Static Web App, a new folder with name .github/workflows will be created in the GitHub Repository.

    enter image description here

    It contains the same workflow file (preview file), which we saw while creating the Static 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 existing workflow file.

    • We can use either Powershell/Azure CLI commands to update the Appsettings.

    az staticwebapp appsettings set --name YourStaticWebAppname --setting-names "message=HelloEveryOne"
    

    ***Sample code for Updating App settings: ***
    Before Build and deploystep in Workflow, add the below steps.

    - name: Build And Deploy
    - run : Your Update appsettings Script 
    

    To edit the Workflow file, click on the .github/workflow => .yml file

    enter image description here

    References 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search