Search code examples
jsonazure-devopsazure-pipelinesvariable-substitution

Azure DevOps Pipeline Json Variable Substitution - Microsoft.Hosting.Lifetime


How can I change the value of Logging:LogLevel:Microsoft.Hosting.Lifetime using a Json Variable Substitution task in Azure DevOps?

This article...

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=azure-devops&tabs=Classic

...states:

If a variable name includes periods ("."), the transformation will attempt to locate the item within the hierarchy. For example, if the variable name is first.second.third, the transformation process will search for:

"first" : {
  "second": {
    "third" : "value"
  }
}

as well as "first.second.third" : "value".

Neither of these would be able to target a nested value with periods (.) in the name? Right?


Solution

  • Neither of these would be able to target a nested value with periods (.) in the name? Right?

    Sorry but I'm afraid you can't be able to do that with JSON variable substitution for now. The official document has stated that the JSON variable substitution option doesn't support variables whose names contain periods. It's not supported by design, and it's already documented in the Notes.

    As alternative workarounds:

    1. You can define the variable name in another format, something like Logging:LogLevel:Microsoft_Hosting_Lifetime.

    2. Try using Replace Token task to change the value of Logging:LogLevel:Microsoft.Hosting.Lifetime. This task should work for your scenario. For more details you can check this issue.

    3. Also you can submit a feature request about JSON variable substitution option on our UserVoice site, which is our main forum for product suggestions. The product team would provide the updates if they view it. Thank you for helping us build a better Azure DevOps.