Create branch preview environments in Azure Static Web Apps

You can configure your site to deploy every change made to branches that aren't a production branch. This preview deployment is published at a stable URL that includes the branch name. For example, if the branch is named dev, then the environment is available at a location like <DEFAULT_HOST_NAME>-dev.<LOCATION> You can delete a branch environment in the portal via the Environments tab of your static web app.


To enable stable URL environments, make the following changes to your configuration.yml file.

  • Set the production_branch input to your production branch name on the static-web-apps-deploy job in GitHub action or on the AzureStaticWebApp task. This action ensures changes to your production branch are deployed to the production environment, while changes to other branches are deployed to a preview environment.
  • List the branches you want to deploy to preview environments in the trigger array in your workflow configuration so that changes to those branches also trigger the GitHub Actions or Azure Pipelines deployment.
    • Set this array to ** for GitHub Actions or * for Azure Pipelines if you want to track all branches.


The following example demonstrates how to enable branch preview environments.

name: Azure Static Web Apps CI/CD

      - main
      - dev
      - staging
    types: [opened, synchronize, reopened, closed]
      - main

    name: Build and Deploy Job
      - uses: actions/checkout@v2
          submodules: true
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
          production_branch: "main"


The ... denotes code skipped for clarity.

In this example, the preview environments are defined for the dev and staging branches. Each branch is deployed to a separate preview environment.

Next steps