Static web app to use Service connection

Bombbe 1,441 Reputation points
2023-12-28T12:23:23.58+00:00

Hello,

How can I use a service connection (service principal) in the deployment of a static web app from Azure DevOps? When creating static web apps from the portal and taking code from Azure DevOps, it creates a Personal Access Token (PAT). Can I use service connections instead of PATs during the first deployment? If so, how do I set it up or does it require additional steps or steps in some kind of different order ?

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,178 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andriy Bilous 11,821 Reputation points MVP Volunteer Moderator
    2023-12-29T06:41:31.9933333+00:00

    Hello @Bombbe

    When using Azure DevOps to deploy Static WebApp you can use AzureStaticWebApp@0 task
    It supports Azure Static Web Apps api token(azure_static_web_apps_api_token) to authenticate between Azure DevOps and Static WebApp.

    Here is an example

    trigger:
      - main
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
      - checkout: self
        submodules: true
      - task: AzureStaticWebApp@0
        inputs:
          app_location: '/build'
          api_location: 'api'
          output_location: '/output'
          azure_static_web_apps_api_token: $(deployment_token)
    

    References:
    https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-static-web-app-v0?view=azure-pipelines

    https://www.daveabrock.com/2021/04/01/static-web-apps-azure-pipelines/

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. brtrach-MSFT 17,741 Reputation points Microsoft Employee Moderator
    2023-12-30T05:03:50.77+00:00

    @Bombbe Thank you to @Andriy Bilous for providing a very helpful answer. I have just the one below item to add to their wonderful answer. Otherwise, let either of us know if you have any further questions.

    Please note that the service principal must have the Contributor role on the subscription or resource group that contains your static web app to be able to deploy it. Also, make sure that you have the necessary permissions to create a service principal and service connection in Azure DevOps.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.