Search code examples
octopus-deployoctopus

Structured variable replacement not working for web.config (XML)


Octopus Server 2021.1

I’m attempting to use the structured variable replacement feature to replace parts of a web.config (XML) file, but it only tries to read the read the file as Json and Yaml but not Xml. The variable is called the following: /configuration/system.webServer/rewrite/rules/rule/action/@url, where @url is the attribute of the element. I have tried many things but cant seem to get it to treat the web.config file as an XML file - does anyone have experience getting this type of substitution to work in Octopus Deploy?

The code in the web.config looks like this:

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <rewrite>
      <rules>
        <rule name="ReverseProxyInboundRule1" stopProcessing="true">
          <match url="^api/(.*)" />
          <action type="Rewrite" url="http://localhost:8053/api/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
||15:22:17   Verbose  |       The file at C:\Octopus\Work\20210612032325-158854-2674\staging\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.|
|---|---|
||15:22:17   Verbose  |       Attempting structured variable replacement on file C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config with format Json|
||15:22:17   Verbose  |       The file at C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config couldn't be parsed as Json: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.|
||15:22:17   Verbose  |       Attempting structured variable replacement on file C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config with format Yaml|
||15:22:17   Info     |       No structures have been found that match variable names, so no structured variable replacements have been applied.|
||15:22:17   Info     |       Structured variable replacement succeeded on file C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config with format Yaml|
||15:22:17   Verbose  |       The file at C:\Octopus\Work\20210612032325-158854-2674\staging\Views\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.|
||15:22:17   Verbose  |       Attempting structured variable replacement on file C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config with format Json|
||15:22:17   Verbose  |       The file at C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config couldn't be parsed as Json: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.|
||15:22:17   Verbose  |       Attempting structured variable replacement on file C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config with format Yaml|
||15:22:17   Info     |       No structures have been found that match variable names, so no structured variable replacements have been applied.|
||15:22:17   Info     |       Structured variable replacement succeeded on file C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config with format Yaml|

Solution

  • This should be working based on the docs.

    It could be a bug. The best action now is to email [email protected] with the details and full log file for diagnosis.

    With .NET config files, there is an alternate pattern you can use to get the same result detailed in the docs that involves combining a config file transform and substitute variable templates in files.