Hi,
I am trying to deploy a static webapp (Blazor WASM) using Azure Pipelines.
I have the packaged application as a pipeline artifact from a previous stage in my deployment pipeline. The basic steps I am doing is:
- Download the artifact
- Extract the zip into an empty directory
- Get the deployment Token using AzureCLI Task
- Deploy the application
This works as expected. Nevertheless, the current requirements brought me to the point that I need to modify the appsettings.json before deploying with some details for the environment in which the application is deployed.
To achieve that I added a AzureCLI Task after the zip extraction task in my pipeline, which modifies the appsettings.json in the local directory on the agent. This seems to work find (For debugging purposes I added a step after the retrieval of the deployment token, to display the contents of the appsettings.json file - it is modified here).
Unfortunately in the deployed web app, I always find the original appsettings.json and I am unable to figure out why and where the pipeline gets that one from.
steps:
- task: DownloadBuildArtifacts@0
displayName: Download Build Artifact
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: '${{ parameters.artifactName }}'
downloadPath: '${{ parameters.workingDirectory }}'
- task: ExtractFiles@1
displayName: Extract Artifact
inputs:
archiveFilePatterns: '${{ parameters.workingDirectory }}/**/*.zip'
destinationFolder: '${{ parameters.workingDirectory }}/.deploy/${{ parameters.artifactName }}'
cleanDestinationFolder: true
overwriteExistingFiles: true
- task: AzureCLI@2
displayName: Configure appsettings.json
inputs:
azureSubscription: ${{ parameters.subscriptionName }}
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az config set extension.use_dynamic_install=yes_without_prompt
az extension add --name containerapp
$path = Join-Path '${{ parameters.workingDirectory }}' '.deploy' '${{ parameters.artifactName }}' 'wwwroot' 'appsettings.json'
$file = Get-Item $path
if (!$file.exists)
{
Write-Host 'appsettings file does not exist!'
}
else
{
$appenv = az containerapp env show -n ${{ parameters.environment }}-${{ parameters.region }} -g rg-${{ parameters.environment }}-${{ parameters.region }}-backend | ConvertFrom-Json
$appsettings = Get-Content $file | ConvertFrom-Json
# set values
Write-Host "Setting Environment.Name to ${{ parameters.environment }}"
$appsettings.Environment.Name = '${{ parameters.environment }}'
Write-Host "Environment.Name = $($appsettings.Environment.Name)"
Write-Host "Setting Environment.Region to ${{ parameters.region }}"
$appsettings.Environment.Region = '${{ parameters.region }}'
Write-Host "Environment.Region = $($appsettings.Environment.Region)"
Write-Host "Setting Environment.Backend to $($appenv.properties.defaultDomain)"
$appsettings.Environment.Backend = $appenv.properties.defaultDomain
Write-Host "Environment.Backend = $($appsettings.Environment.Backend)"
$json = $appsettings | ConvertTo-Json
Write-Host $json
Set-Content -Path $file -Value $json
Get-Content $file | Write-Host
}
- task: AzureCLI@2
displayName: Retrieve Deployment Token
inputs:
azureSubscription: ${{ parameters.subscriptionName }}
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$key = (az staticwebapp secrets list -n ${{ parameters.webAppName }} --query "properties.apiKey").Replace('"', "")
Write-Host "##vso[task.setvariable variable=deploymentToken]$key"
- task: AzureStaticWebApp@0
displayName: 'Deploy WebApp ${{ parameters.artifactName }} to ${{ parameters.webAppName }}'
inputs:
app_location: '${{ parameters.workingDirectory }}/.deploy/${{ parameters.artifactName }}/wwwroot'
skip_api_build: true
azure_static_web_apps_api_token: $(deploymentToken)