本文介绍了如何在 XML 配置文件中指定 Octopus 内置变量名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在测试 Octopus Deploy,所以我们制作了一个示例 web.config 文件,我们在不同的环境中安装和转换.web.config 转换和自定义变量的使用工作正常,但我无法替换内置 Octopus 变量.以下是 web.config 中 XML 部分的示例:

We are testing Octopus Deploy, so we made a sample web.config file that we installed and transform in different environments. web.config transformation and use of custom variable work fine, but I can't get build-in Octopus variables to be substituted. Here's an example of of XML section in web.config:

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="environmentTransform" value="" />
    <add key="EnvironmentVariable1" value="$OctopusEnvironmentName" />
    <add key="EnvironmentVariable2" value="$(OctopusEnvironmentName)" />
    <add key="EnvironmentVariable3" value="$(Octopus.Environment.Name)" />
    <add key="EnvironmentVariable4" value="$Octopus.Environment.Name)" />
    <add key="EnvironmentVariable5" value="$OctopusParameters[&quot;Octopus.Environment.Name&quot;]" />
    <add key="MachineVariable1" value="$Octopus.Machine.Name" />
    <add key="MachineVariable2" value="#(Octopus.Machine.Name)" />
    <add key="MachineVariable3" value="#OctopusMachineName" />
    <add key="CustomVariable" value="CustomVariable" />
  </appSettings>

这里是 web.Dev.config,以环境命名:

And here's web.Dev.config, named after the environment:

  <appSettings>
    <add key="environmentTransform" value="Dev" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
  </appSettings>

结果如下:

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="environmentTransform" value="Dev" />
    <add key="EnvironmentVariable1" value="$OctopusEnvironmentName" />
    <add key="EnvironmentVariable2" value="$(OctopusEnvironmentName)" />
    <add key="EnvironmentVariable3" value="$(Octopus.Environment.Name)" />
    <add key="EnvironmentVariable4" value="$Octopus.Environment.Name)" />
    <add key="EnvironmentVariable5" value="$OctopusParameters[&quot;Octopus.Environment.Name&quot;]" />
    <add key="MachineVariable1" value="$Octopus.Machine.Name" />
    <add key="MachineVariable2" value="#(Octopus.Machine.Name)" />
    <add key="MachineVariable3" value="#OctopusMachineName" />
    <add key="CustomVariable" value="Value for maeaint01" />
  </appSettings>

如您所见,Octopus 变量没有被替换.知道为什么吗?

As you can see, Octopus variables are not replaced. Any idea why?

推荐答案

Octopus 的配置文件变量替换仅适用于设置 key,而不适用于值.如果您创建如下设置:

Octopus's config file variable substitution works only on the setting key, not the value. If you create a setting like:

然后 value 将在部署时设置.

then the value will be set at deployment time.

您尝试使用其他方法的方法当然是合理的,但与 Octopus 当前使用配置文件的方式不同.

What you're attempting with the other approaches is reasonable of course, but not how Octopus currently works with config files.

我们在 2.0 中通过新的解析器和新功能(#{if ...#{each 等)增强了我们的变量替换处理- 你的问题激励我起草这个提案,它可能会更好地解决这种用法.

We've enhanced our variable substitution processing in 2.0 with a new parser and new capabilities (#{if ..., #{each and so-on) - your question inspired me to draft up this proposal which might address this usage better.

这篇关于如何在 XML 配置文件中指定 Octopus 内置变量名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 01:18