|
| 1 | +--- |
| 2 | +title: Create named preview environments in Azure Static Web Apps |
| 3 | +description: Expose stable URLs for named environments 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: 04/27/2022 |
| 9 | +ms.custom: template-how-to |
| 10 | +--- |
| 11 | + |
| 12 | +# Create named preview environments in Azure Static Web Apps |
| 13 | + |
| 14 | +You can configure your site to deploy every change to a named environment. This preview deployment is published at a stable URL that includes the environment name. For example, if the environment is named `release`, then the preview is available at a location like `<DEFAULT_HOST_NAME>-release.<LOCATION>.azurestaticapps.net`. |
| 15 | + |
| 16 | +## Configuration |
| 17 | + |
| 18 | +To enable stable URL environments with named deployment environment, make the following changes to your [configuration file](configuration.md). |
| 19 | + |
| 20 | +- Set the `deployment_environment` input to a specific name on the `static-web-apps-deploy` job in GitHub action or on the AzureStaticWebApp task. This ensures all changes to your tracked branches are deployed to the named preview environment. |
| 21 | +- 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. |
| 22 | + - Set this array to `**` for GitHub Actions or `*` for Azure Pipelines if you want to track all branches. |
| 23 | + |
| 24 | +## Example |
| 25 | + |
| 26 | +The following example demonstrates how to enable branch preview environments. |
| 27 | + |
| 28 | +# [GitHub Actions](#tab/github-actions) |
| 29 | + |
| 30 | +```yml |
| 31 | +name: Azure Static Web Apps CI/CD |
| 32 | + |
| 33 | +on: |
| 34 | + push: |
| 35 | + branches: |
| 36 | + - "**" |
| 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 | + deployment_environment: "release" |
| 56 | +``` |
| 57 | +# [Azure Pipelines](#tab/azure-devops) |
| 58 | +
|
| 59 | +```yml |
| 60 | +trigger: |
| 61 | + - "*" |
| 62 | + |
| 63 | +pool: |
| 64 | + vmImage: ubuntu-latest |
| 65 | + |
| 66 | +steps: |
| 67 | + - checkout: self |
| 68 | + submodules: true |
| 69 | + - task: AzureStaticWebApp@0 |
| 70 | + inputs: |
| 71 | + ... |
| 72 | + deployment_environment: "release" |
| 73 | +``` |
| 74 | +
|
| 75 | +--- |
| 76 | +
|
| 77 | +> [!NOTE] |
| 78 | +> The `...` denotes code skipped for clarity. |
| 79 | + |
| 80 | +In this example, changes to all branches will be deployed to the `release` named preview environment. |
| 81 | + |
| 82 | +## Next Steps |
| 83 | + |
| 84 | +> [!div class="nextstepaction"] |
| 85 | +> [Review pull requests in pre-production environments](./review-publish-pull-requests.md) |
0 commit comments