yamlblazor-webassemblyazure-pipelines-yamlazure-static-web-app

Azure Static Web App not recognizing staticwebapp.config.json in Blazor WASM app when deployed via Azure Pipelines


I have a standalone Blazor WASM app that I am trying to deploy to an Azure Static Web App resource via CI/CD.

My app deploys, but my navigationg fallback rules aren't working. I have a staticwebapp.config.json file located in my wwwroot folder with he following content.

{
  "navigationFallback": {
    "rewrite": "/index.html",
    "exclude": [ "*.{css,scss,js,png,gif,ico,jpg,svg}" ]
  }
}

My app loads fine, but I am unable to login, because the authetnication/login-callback path is returnign a 404.

I have also tried moving staticwebapp.config.json to the root of my project, but I get the same result.

When I use "Diaganose and Solve Problems" in the Azure Portal, I can see that my configuration file is not being read correctly.

Azure Static Web App Configuration

Admitedly, I don't know alot about Azure Pipelines and creating YAML scripts, so I am sure I am missing something.

I am deplying the app using PublishPipelineArtifact@1. I experimented with AzureStaticWebApp@0, but I couldn't get it to work.

If someone could point me to a repo or exampel code with a full working YAML example, that would be great.


Solution

  • I created a simple Blazor WebAssembly Standalone App with Azure Ad and deployed it to Azure Static Web App using Azure DevOps Pipelines.

    Make sure that staticwebapp.config.json and appsettings.json is located under wwwroot folder.

    enter image description here

    In your azure-pipeline.yml define correct app location and output location.

     app_location: "/"
     output_location: "wwwroot"
    

    Below is my complete azure-pipeline.yml file for reference.

    name: Azure Static Web Apps CI/CD
    pr:
      branches:
        include:
          - main
    trigger:
      branches:
        include:
          - main
    jobs:
    - job: build_and_deploy_job
      displayName: Build and Deploy Job
      condition: or(eq(variables['Build.Reason'], 'Manual'),or(eq(variables['Build.Reason'], 'PullRequest'),eq(variables['Build.Reason'], 'IndividualCI')))
      pool:
        vmImage: ubuntu-latest
      variables:
      - group: <GroupName>
      steps:
      - checkout: self
        submodules: true
      - task: AzureStaticWebApp@0
        inputs:
          azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN)
          app_location: "/"
          api_location: "Api" 
          output_location: "wwwroot"
    

    Re-run the pipeline again it will resolve the issue.

    After the pipeline completes successfully, I am able to redirect to the login page.

    Output:

    enter image description here

    enter image description here