我需要在远程计算机上的xml文件中更改节点(因配置而为true或false),在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
一切正常,但我文件中的字段值为空,但应该为true或false(
我不能使静态为真或假。它应该是因为Teamcity中的一些配置而改变
也许我可以从teamcity anf获取构建配置的名称如果cat_1而不是运行“true”如果cat_2而不是“false”但我不知道该怎么做
答案 0 :(得分:0)
所以,我发现我的脚本layoutrel.ps1里面会有chamge节点,请不要带参数$ hiddenfunctionality为什么会这样?当我给$ hiddenfunctionality =“true”时它起作用(