简体   繁体   中英

Azure app settings task in Azure pipeline throws invalid JSON error when supplying with variable

Trying to update Azure Configuration using Azure Pipeline's Azure App Settings task as documented here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-app-service-settings?view=azure-devops .

The link has a sample for appsettings as,

appSettings: |
      [
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "$(Key)",
          "slotSetting": false
        },
        {
          "name": "MYSQL_DATABASE_NAME",
          "value": "$(DB_Name)", 
          "slotSetting": false
        }
      ]

However when we try to supply the same with a variable like this,

  - task: AzureAppServiceSettings@1
    displayName: Azure App Service Settings
    inputs:
        azureSubscription: $(subscriptionName)
        appName: $(appServiceName)  
        resourceGroupName: $(resourceGroupName)       
        appSettings: $env:azureConfigurationSettings

we receive error as

##[error]Error: Application Settings object is not a valid JSON.

I have verified $env:azureConfigurationSettings is correct JSON via JSON validator as well as it successfully parses JSON.Parse(theActualValue). When we put the actual value of variable as hardcoded string there is no error and the configuration gets updated.

Need help in determining,

  1. If this Azure appsettings task supports the supply of variable and if it does, what is the correct syntax. The variable is coming from Powershell script.

I looked at the source code at

https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureAppServiceSettingsV1/azurewebappsettings.ts

and logically I think it should work.

I finally figured it out. You would need to have the content of your $env:azureConfigurationSettings as one single line (JSON without line breaks) then it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM