Murdock
Murdock

Reputation: 4662

Azure Static Web App: transform Blazor webassembly appsettings.json in Azure DevOps

I have a static blazor web app that has the following structure:

enter image description here

and the following setting in appsettings.json:

{
  "ApiUrl": "http://localhost:7071/api/"
}

I also have a Azure DevOps pipeline with the following yaml:

trigger:
  - main

pool:
  vmImage: ubuntu-latest

steps:
  - checkout: self
    submodules: true
  - task: AzureStaticWebApp@0
    inputs:
      app_location: '/Atlas.Blazor'
      api_location: '/Atlas.InternalHost'
      output_location: '/wwwroot'
      azure_static_web_apps_api_token: $(deployment_token)

How do I update the appsettings during deployment with a variable?

Upvotes: 3

Views: 1198

Answers (2)

Murdock
Murdock

Reputation: 4662

At the end this worked

trigger:
  - main

pool:
  vmImage: ubuntu-latest

  
steps:
  - checkout: self
    submodules: true
      
  - task: FileTransform@1
    inputs:
      folderPath: '$(System.DefaultWorkingDirectory)/Atlas.Blazor/wwwroot'
      fileType: 'json'
      targetFiles: '**/appsettings.json'
  - task: AzureStaticWebApp@0
    inputs:
      app_location: '/Atlas.Blazor'
      api_location: '/Atlas.InternalHost'
      output_location: '/wwwroot'
      azure_static_web_apps_api_token: $(deployment_token)

Upvotes: 4

JukkaK
JukkaK

Reputation: 1175

I don't think it's possible to manipulate the configuration file during the build/deployment that happens within the Oryx-container. What you could do is to manipulate the file during the pipeline run by, for example, tokenizing the environment-specific configuration values and replacing the tokens during the pipeline run. To achieve this with single json-file (ie. having just a file with the localhost-value stored in version control) you could use tokenizer- and replace tokens -task from Colin's ALM Corner extension collection (https://marketplace.visualstudio.com/items?itemName=colinsalmcorner.colinsalmcorner-buildtasks). Another option would be to have multiple environment-specific configuration files in version control and just copying a specific one over the appsettings.json during the pipeline run.

Not sure if Static Web App environment variables could be utilized here, but adding it here if someone using GitHub Actions is looking for this - they are not yet supported by Azure Pipelines.

https://learn.microsoft.com/en-us/azure/static-web-apps/build-configuration?tabs=github-actions#environment-variables

Upvotes: 1

Related Questions