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>.azurestaticapps.net
. You can delete a branch environment in the portal via the Environments tab of your static web app.
Configuration
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 thestatic-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.
- Set this array to
Example
The following example demonstrates how to enable branch preview environments.
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- main
- dev
- staging
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
jobs:
build_and_deploy_job:
...
name: Build and Deploy Job
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
...
production_branch: "main"
Note
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.