In my appSettings.json file I have a section named "ItemList" which is in source control as "ItemList": [ ]
In my build definition I'm attempting to add two values to the array "One" and "Two" using variable substitution. I've declared two variables "ItemList.0" with a value of "One" and "ItemList.1" with a value of "Two" but the values are not being added to the appSettings.json during the transformation process.
What is the supported method, if any, of setting the values for an empty array during the File Transformation and Variable Substitution phase of an Azure App Service Deploy step?
â Do not edit this section. It is required for docs.microsoft.com â GitHub issue linking.
I am also quite interested in previous question: can we add items to an array (not only replace existing items)?
It follows JSONPath notation. To substitute JSON variables that are nested or hierarchical, specify them using JSONPath expressions. Depending on how your itemList nested, you need provide fully qualified JSONPath as the variable name in the release. Just providing itemList will look for top level node in the JSON.
For example, to replace the value of âConnectionStringâ in the sample below, you need to define a variable as âData.DefaultConnection.ConnectionStringâ in the build or release pipeline (or release pipeline's environment).
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\SQLEXPRESS;Database=MyDB;Trusted_Connection=True"
}
}
}
We are talking about adding a new value, not replacing an already existant one.
In following json I would like to add a third user
{
âUsersâ: [âuser1â , âuser2â]
}
I can replace user1 by defining a variable Users.0 and giving a value. However I was expecting to add a new user to array defining variable Users.2
Do you plan to support this scenario?
The code looks for the JSONPath matching the variable name and substitutes the value and doesnât insert new.
Currently we are working on issues that impact broader set of customers and it will be a while before we can get to it. We do encourage contributions, if you are open, please feel free to raise a PR
@RoopeshNair , I see this was closed, but I have also been looking for a solution for a while. Is there somewhere separate to track this feature request?
Octopus has a feature where it is possible to replace the whole node with a new list. It is crude, but it works for these examples. It would be great if that could be implemented i Devops as well.
I added a feature request for this:
https://github.com/Microsoft/azure-pipelines-tasks/issues/9257
Most helpful comment
@RoopeshNair , I see this was closed, but I have also been looking for a solution for a while. Is there somewhere separate to track this feature request?