Configuration variables for non-standard configs

Hi!

I’m looking to utilize configuration variables for a highly used .config file in our program. However, this .config is not utilizing the “key” value for the key pairs and instead is simply a list of “name=value” with line-breaks all encapsulated in a tag. Is there any way to use the Configuration Variables functionality in such a way where it looks for any instance of the key name in the file, regardless of whether it’s formed like a standard xml config? I’d really rather not have to write a big long Regex powershell script to handle this.

Thank you,
Michael Gutierrez

Hi Michael,

Thanks for getting in touch!

Usually I’d recommend using Configuration Transformation in this case, but it sounds like your config file is essentially one large whitespace-sensitive string inside a single XML tag? If so, we can’t really treat it like an XML file.

One way you might be able to do this is by using the Substitute variables in files feature to simply do a substitution of any #{VariableName} style variable in any file. If your config file was to contain variableName=#{variableValue} pairs, that find-replace would work.

If you need to keep values in your config file while you’re developing, that could be difficult.

If you are able to send me the file, I might be able to come up with some other options?

Kind Regards,
Damo

Hi Michael,

I realised my previous message might be slightly misleading.

I meant to say:

If your config file was to contain name=#{variableName} pairs, that find-replace would work. If you have a variable called variableName, the value will replace #{variableName} in your file.

Thanks,
Damo

Great, Thanks! We might end up with some combination of config transforms and substituting variables in the files. Such as having a file.config and a file.release.config that only gets looked at when Octopus is touching it. The release file would have the #{} variables in it while the normal one would have the basic localhost stuff the devs use. Below is something of a fake version of what some of this file might look like. Let me know if anything jumps out at you from that, and thanks again!


<config
                 config.target="SomeServer"
                 EnableSomethingSpecial="true"
                 WTF.EndpointURL="www.notasite.com"
                 SSRS.ReportingStuff="\\PathTo\ReportingStuff\
                 SQL.ConString="Application Name=AName; Data Source=SourceServer;Initial Catalog=TargetCatalog;Connect Timeout=60;Integrated Security=SSPI"
                 Common.Env="Dev"
                 Common.Logo="CoolLogo.jpg"
/>

Hi Michael,

That looks like a workable solution to me!

If you’re using attributes that belong to the config element in XML, you may be able to use configuration transforms to do the work. Your file.release.config could reset those attributes to the Octopus variables you want to use. Variable replacement happens before transformation, but if you targeted the transform file in the variable replacement feature, it would still work.

Good luck!
Damo