Manage variable

Hi,
I am deploying web api project by creating its nuget package and pushing to octopus using tfs. Octopus is deploying this package to appropriate web server successfully. This package contains web.config which has section called as MessageConfig which contain items which has parameters like TypeName , Enabled, Secrete as follows :




I want to add this Messageconfig item dynamically on release without doing changes in web.config or in web.release.config so that no package is created each time.

Solution to this is I have done is like created loop script in web.release.config as follow :

#{each item in MessageConfigList} #{/each}

and created appropriate variables in octopus as follows :
Name - value
MessageConfigList[1].TypeName - "TestEvent1"
MessageConfigList[1].Secret - "XXX"
MessageConfigList[1].Enabled - "true"
MessageConfigList[2].TypeName - "TestEvent2"
MessageConfigList[2].Secret - "YYY"
MessageConfigList[2].Enabled - “false”

which will add following to web.config when I create release :






But with this if I want to add 100 items then I have to create 300 variables and in that also if environment is different then have to create variable accordingly.This become very hectic. Can you please suggest some alternate solution to this ?

Thanks,
Dipika

Hi Dipika,

Thanks for reaching out. The two methods you described are the only way to dinamically add items to a config file during deployments:

A) Adding them directly to the transform file Web.Release.config.
B) Adding them with multiple variables.

I personally prefer (A) as the changes will be saved in source control , making them visible for anyone involved with the code. This will of course implicate having a new build and artifact created with every commit, which is a practice we definitely recommend.

You could also use our API to insert new variables that you could get from a file for example, but in the end this would mean maintaining yet another file, in which case I’d still recommend to go with approach A instead.

Sorry if its not the answer you were looking for. Please let me know if you have any extra questions or if there’s anything else I can help with.

Best regards,
Dalmiro

Notice:

This issue has been closed due to inactivity. If you encounter the same or a similar issue and require help, please open a new discussion (if we asked for logs or extra details in this thread, consider including them in the new thread). If you are the creator of this thread and believe it should not be closed let us know via our support email.