【问题标题】:Teamcity change node in xml filexml文件中的Teamcity更改节点
【发布时间】:2013-09-20 09:51:50
【问题描述】:

我需要在远程计算机上的 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”,但我不知道该怎么做

【问题讨论】:

  • 只是一个野刺,当您调用 Set-Layout 函数时,您是否尝试将 $true 替换为“true”。当 $true 变量通过脚本和函数传递时,可能会发生一些事情。
  • 不,我不尝试,你告诉在 teamcity "true" 中尝试调用函数而不是 $true?
  • 是的,试试看有没有什么发生

标签: powershell configuration build teamcity


【解决方案1】:

所以,我发现我的脚本 layoutrel.ps1 会改变节点,不要带参数 $hiddenfunctionality 为什么会这样?当我为 $hiddenfunctionality="true" 提供时,它可以工作(

【讨论】:

    猜你喜欢
    • 2013-03-26
    • 2010-09-24
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多