Structured configuration variables for .config file how to define project variable

I want to replace variables inside web.config file with variables defined in Octopus project. I am using Octopus Cloud and Structured configuration variables for variable replacement. Below is the log output.

Performing variable substitution on ‘C:\Octopus\Tentacle\Work\20210712090800-1719-32\Script.ps1’
July 12th 2021 19:10:52Verbose
The file at C:\Octopus\Tentacle\Work\20210712090800-1719-32\hf.website.develop\Website\Web.config does not match any known filename patterns. The file will be tried as multiple formats and will be treated as the first format that can be successfully parsed.
July 12th 2021 19:10:52Verbose
Attempting structured variable replacement on file C:\Octopus\Tentacle\Work\20210712090800-1719-32\hf.website.develop\Website\Web.config with format Json
July 12th 2021 19:10:52Verbose
The file at C:\Octopus\Tentacle\Work\20210712090800-1719-32\hf.website.develop\Website\Web.config couldn’t be parsed as Json: Unexpected character encountered while parsing value: <. Path ‘’, line 0, position 0.
July 12th 2021 19:10:52Verbose
Attempting structured variable replacement on file C:\Octopus\Tentacle\Work\20210712090800-1719-32\hf.website.develop\Website\Web.config with format Xml
July 12th 2021 19:10:52Info
No structures have been found that match variable names, so no structured variable replacements have been applied.
July 12th 2021 19:10:52Info
Structured variable replacement succeeded on file C:\Octopus\Tentacle\Work\20210712090800-1719-32\hf.website.develop\Website\Web.config with format Xml
July 12th 2021 19:10:52Verbose
Executing ‘C:\Octopus\Tentacle\Work\20210712090800-1719-32\Script.ps1’

Below is my web.config file

<?xml version="1.0" encoding="utf-8"?>

Variable get replaced with
/configuration/appSettings/add[@key=‘centralApiBaseUrl’]/@value → My_Value

but not with
centralApiBaseUrl → My_Value

Which is correct way to define the variables in Octopus project?

Variable replacement happens with .NET Configuration Variables option but Octopus scans for all .config files before it does replacement.

Hi @vaibhavn,

Thanks for getting in touch!

If the values that you want to replace are within the appSettings, connectionStrings, or applicationSettings sections then the .NET Configuration Variables option would be the best option as it does not require any changes to your web.config file prior to uploading it to Octopus.

Is the fact that it scans all *.config files causing a problem?

If the above isn’t an option, would you be able to provide a screenshot of how your variable is configured within Octopus and the relevant snippet from your web.config file? This will allow me to get a better picture of the situation.

Regards,
Paul

Regarding
Is the fact that it scans all *.config files causing a problem?
No. Is this the best way to do it? My changes are only inside appSettings.

Below is example where variable substitution works.
Octopus Project Variable:
/configuration/appSettings/add[@key=‘cachingEnabled’]/@value

Octopus Project Variable Value:
true

<?xml version="1.0" encoding="utf-8"?

Regarding
Is the fact that it scans all *.config files causing a problem?
No. Is this the best way to do it?

It is how I would do it yes.

Typically, the more advanced features such as Structured configuration variables and Substitute Variables in templates are best used if the value you want to replace is outside of the sections that .NET Configuration Variables can replace.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.