Hi Alex,
Thanks for getting back again. I may have misunderstood exactly where you were getting stuck here. Hopefully I’m understanding now and the below will provide a better explanation.
So it sounds like you are not entirely clear about the where and how you could get the #{jsonSubstitutionVariable}
into your file. (As a note, this variable could be called anything and simply points to a variable in your Octopus Project Variables)
As a further note, the json substitution you are using in your example IotCoreRegistry:Uir:Port
is a great way to substitute single values in your json file. However, this feature has no way to remove entire properties/lines such as “Type”: “File”,
Which is where this sort of workaround comes in.
So assuming you have your current file, as you initially described to me. appconfig.json
Example for my LOCAL- Enviroment .json:
“IotCoreRegistry”: {
“Uri”: {
“Scheme”: “https”,
“Host”: “registry.iotcore”,
“Port”: 443
},
“Service”: {
“ComponentId”: “Master/TestService”,
“ServiceId”: “Monitoring”,
“Protocol”: “tcp”
},
“Type”: “File”,
“File”: “C:\Server\log.txt”
},
To have Octopus remove lines from the above appconfig.json
based on the environment you are deploy to, you can package your appconfig.json
file without these lines at all. And instead, have it already pointing to a variable in your project.
So you could package your .json file to contain the following:
“IotCoreRegistry”: {
“Uri”: {
“Scheme”: “https”,
“Host”: “registry.iotcore”,
“Port”: 443
},
#{jsonSubstitutionVariable}
Then in Octopus you can create a single variable (again it can be named anything, just so long as it’s the same string as in the .json file.) which contains multiple values, pointing to the rest of your .json parameters which may be different depending on environment. In my example below one is scoped to Dev and the other Test.
When I use the “Substitute Variables in Files” feature I mentioned previously and point to my appsettings.json, Octopus will identify the variable syntax #{}
and match it to your project variable based on variable name and scoping.
This is currently the best method we have for “removing/adding” lines in your .json file based on environment.
I hope I have done a better job of explaining this workaround idea and how you can get the variable into your JSON file.
If you are still stuck on this or have any further questions at all, please don’t hesitate to let me know.
Best regards,
Daniel