|
| 1 | +--- |
| 2 | +title: Create branch preview environments in Azure Static Web Apps |
| 3 | +description: Expose stable URLs for specific branches to evaluate changes in Azure Static Web Apps |
| 4 | +author: craigshoemaker |
| 5 | +ms.author: cshoe |
| 6 | +ms.service: static-web-apps |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 03/29/2022 |
| 9 | +ms.custom: template-how-to |
| 10 | +--- |
| 11 | + |
| 12 | +# Create branch preview environments in Azure Static Web Apps |
| 13 | + |
| 14 | +You can configure your site to deploy every change made to branches that aren't a production branch. This preview deployment lives for the entire lifetime of the branch and 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`. |
| 15 | + |
| 16 | +## Configuration |
| 17 | + |
| 18 | +To enable stable URL environments, make the following changes to your [configuration file](configuration.md). |
| 19 | + |
| 20 | +- Set the `production_branch` input on the `static-web-apps-deploy` GitHub action to your production branch name. This ensures changes to your production branch are deployed to the production environment, while changes to other branches are deployed to a preview environment. |
| 21 | +- List the branches you want to deploy to preview environments in the `on > push > branches` array in your workflow configuration so that changes to those branches also trigger the GitHub Actions deployment. |
| 22 | + - Set this array to `**` if you want to track all branches. |
| 23 | + |
| 24 | +## Example |
| 25 | + |
| 26 | +The following example demonstrates how to enable branch preview environments. |
| 27 | + |
| 28 | +```yml |
| 29 | +name: Azure Static Web Apps CI/CD |
| 30 | + |
| 31 | +on: |
| 32 | + push: |
| 33 | + branches: |
| 34 | + - main |
| 35 | + - dev |
| 36 | + - staging |
| 37 | + pull_request: |
| 38 | + types: [opened, synchronize, reopened, closed] |
| 39 | + branches: |
| 40 | + - main |
| 41 | + |
| 42 | +jobs: |
| 43 | + build_and_deploy_job: |
| 44 | + ... |
| 45 | + name: Build and Deploy Job |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v2 |
| 48 | + with: |
| 49 | + submodules: true |
| 50 | + - name: Build And Deploy |
| 51 | + id: builddeploy |
| 52 | + uses: Azure/static-web-apps-deploy@v1 |
| 53 | + with: |
| 54 | + ... |
| 55 | + production_branch: "main" |
| 56 | +``` |
| 57 | +
|
| 58 | +> [!NOTE] |
| 59 | +> The `...` denotes code skipped for clarity. |
| 60 | + |
| 61 | +In this example, the preview environments are defined for the `dev` and `staging` branches. Each branch is deployed to a separate preview environment. |
| 62 | + |
| 63 | +## Next Steps |
| 64 | + |
| 65 | +> [!div class="nextstepaction"] |
| 66 | +> [Review pull requests in pre-production environments](./review-publish-pull-requests.md) |
0 commit comments