我需要在远程计算机上的 xml 文件中更改节点(由于配置而为真或假),在 Teamcity 中工作,编写了以下函数
function Set-layout($hiddenfunctionality)
{
$properties = Resolve-Path ".\vsphere\properties.ps1"
. $properties
#Read env.properties
$configFilePath = Resolve-Path ".\environment\prod-env\env.properties"
Write-Host $configFilePath
$file = resolve-path("$configFilePath")
[xml]$doc = Get-Content $file
$node = $doc.SelectSingleNode("/project/property[@name='backend.server']")
$backend_ip = $node.value
$layoutRel = Resolve-Path ".\layout\layoutRel.ps1"
#Remote-Copy $layoutRel "\\$backend_ip\install"
Copy-Item $layoutRel "\\$backend_ip\install"
$dom_user = [string]($domain_name+ "\" + $domain_username)
$Connection = @{"server" = $backend_ip; "username" = $dom_user; "password" = $domain_password}
$rem_command = 'powershell -ExecutionPolicy RemoteSigned . c:\Empower\install\layoutRel.ps1 $hiddenfunctionality'
RemoteCommand $Connection $rem_command
}
此功能正在运行,它调用脚本,该脚本将更改节点“configuration/appSettings/add[@key='opentext.empower.site.enableHiddenFunctionality”的值
Param ($hiddenfunctionality)
Write-Host "Updating C:\Program Files\Opentext\Empower\Web\Web.config"
[System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument
$file = resolve-path("C:\Program Files\Opentext\Empower\Web\web\Web.config")
$xd.load($file)
$xd.SelectNodes("configuration/appSettings/add[@key='opentext.empower.site.enableHiddenFunctionality']").Item(0).SetAttribute( 'value', $hiddenfunctionality)
$xd.Save( $file)
Write-Host "Done"
在我的 teamcity 配置中,执行以下字符串
powershell . %teamcity.build.checkoutDir%\Build\CI_2.0\vsphere\env-handler.ps1; Set-layout $true
一切正常,但我文件中的字段值为空,但应该是真或假(
而且我不能使静态为真或假。由于 Teamcity 中的某些配置,它应该会发生变化
也许我可以从 teamcity anf 中获取构建配置的名称,如果 cat_1 比运行“true”,如果 cat_2 比“false”,但我不知道该怎么做