Home > Back-end >  Staging deployment wit Bitbucket pipeline and Azure Static Web App
Staging deployment wit Bitbucket pipeline and Azure Static Web App

Time:08-27

I could successfully deploy my project into the production environment using the provided documentation https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/static-web-apps/bitbucket.md

pipelines:
  branches:
   main:
    - step: 
        name: Deploy to test
        deployment: test
        script:
          - pipe: microsoft/azure-static-web-apps-deploy:main
            variables:
                APP_LOCATION: '$BITBUCKET_CLONE_DIR'
                OUTPUT_LOCATION: '$BITBUCKET_CLONE_DIR/dist'
                API_TOKEN: $deployment_token​

But there are no information about how to deploy to other environments than production, e.g: staging, qa, release ... With Azure pipeline, the value can be set throw the deployment_environment parameter.

Does anyone have a solution for it?

CodePudding user response:

Just got this working earlier today. I ran into the same issue, looks like they only support Staging environments when using Github or Azure Pipelines. I was able to get this to work by creating multiple Static Web App resources in Azure Portal. Prod gets the "paid" version, develop branch gets the "free" version.

Here is what the pipelines YAML looks like:

pipelines:
  branches:
   develop:
    - step: 
        name: Deploy to staging
        deployment: staging
        script:
          - pipe: microsoft/azure-static-web-apps-deploy:main
            variables:
                APP_LOCATION: '$BITBUCKET_CLONE_DIR/dist'
                API_TOKEN: $deployment_token_beta
   master:
    - step: 
        name: Deploy to production
        deployment: production
        script:
          - pipe: microsoft/azure-static-web-apps-deploy:main
            variables:
                APP_LOCATION: '$BITBUCKET_CLONE_DIR/dist'
                API_TOKEN: $deployment_token

Then I added a new deployment_token_beta to the repo deployment variables using the key from the second web app

CodePudding user response:

If you are using azure static web apps with multiples slots like prod,staging/dev then you have to specify SLOT in your bitbucket-pipelines.yml file

Example :

pipelines:
  branches:
   main:
    - step: 
        name: Deploy to Prod
        deployment: Prod
        script:
          - pipe: atlassian/azure-web-apps-deploy:1.0.1
            variables:
              AZURE_APP_ID: $AZURE_APP_ID
              AZURE_PASSWORD: $AZURE_PASSWORD
              AZURE_TENANT_ID: $AZURE_TENANT_ID
              AZURE_RESOURCE_GROUP: '<string>'
              AZURE_APP_NAME: '<string>'
              ZIP_FILE: '<string>'
              SLOT: 'PROD' **# set the slot name of your webapp.**
              # DEBUG: '<boolean>' # Optional.

   Staging:
    - step: 
        name: Deploy to Staging
        deployment: Staging
        script:
          - pipe: atlassian/azure-web-apps-deploy:1.0.1
            variables:
              AZURE_APP_ID: $AZURE_APP_ID
              AZURE_PASSWORD: $AZURE_PASSWORD
              AZURE_TENANT_ID: $AZURE_TENANT_ID
              AZURE_RESOURCE_GROUP: '<string>'
              AZURE_APP_NAME: '<string>'
              ZIP_FILE: '<string>'
              SLOT: 'STAGING' **# set the slot name of your webapp.**
              # DEBUG: '<boolean>' # Optional.

If you are using the multiple Static Web App resources then you can follow the answer provided by David Torres, you have to create tokens for each web and mention them in variables.

Here is the official link for more information: https://bitbucket.org/atlassian/azure-web-apps-deploy/src/master/

Thanks & Regards

  • Related