Background
I'm using Octopus Deploy in a project with Json configuration variable substitution in one of the processes. The Asp.net core project I contribute takes urls & names from the Json config and adds HttpClient instances to reach several endpoints.
The json looks like this:
"HttpClientFactoryServices": [
{
"Name": "ServiceX",
"Url": "http://serviceXurl"
},
{
"Name": "ServiceY",
"Url": "http://serviceYurl"
},
{
"Name": "ServiceZ",
"Url": "http://serviceZurl"
}
]
I want to edit these Url parts depending on the QA an Prod environments. (on Octopus)
I know there's an array object substitution in Octopus documentation, but I don't feel comfortable to say
HttpClientFactoryServices:0 = {"name":"ServiceX", "url":...}
HttpClientFactoryServices:1 = {"name":"ServiceY", "url":...}
as the array can be altered, the objects it holds can have a different structure in the future. Also it looks like a workaround rather than a proper way.
The Question Is there a way to tell Octopus "find the object which has ServiceX value in the Name property in the array, and set its "Url" property, to http://serviceX-QA if it's in QA environment, and to http://serviceX-prod if it's in Prod environment?
Or do you suggest that I change my approach to the HttpClient & Json config?
Additional info: I used to hold nested objects under HttpClientFactoryServices, before I switched to an object array in the Json config. And it was easy to add property values to them in Octopus, ie:
HttpClientFactoryServices:ServiceX:Url = "http://serviceX"
But in the project code, I had to code "take serviceX from Json, read its Url, add it as an httpClient named service with the name ServiceX". It looked better to iterate through an array of services.
Disclosure: I work for Octopus Deploy.
The simplest solution here would be to use the "Substitute Variables in Files" feature, rather than "JSON Configuration Variables". We have some documentation on that feature here.
Put simply, you can just use a token in your JSON file like #{ServiceXUrl}
, and after enabling the feature and specifying which files you would like transformed, Octopus will find any tokens with matching variable names, and substitute them for you.
Feel free to reach out to us at our usual support channels such as our support forum or email. Details at https://octopus.com/support