【问题标题】:TFSBuild to include an array in parameters to powershellTFSBuild 在 powershell 的参数中包含一个数组
【发布时间】:2012-08-05 09:25:26
【问题描述】:

我有一个 TFS 2010 版本,它调用一个 powershell 脚本进行部署。我为构建脚本定义了几个参数,这些参数效果很好。它们由构建使用,并且还包含在通过 InvokeProcess 控件的 Arguments 属性传递到 Powershell 的参数中。

我现在需要将 powershell 脚本部署到可变数量的服务器,因此我想在 TFS 的参数列表中传递服务器 ID。

在构建定义中,我声明了一个名为 TargetServers 的字符串 [] 类型的新参数。在执行构建之前,我已经从“构建过程参数”对话框中填充了它。

我已将 InvokeProcess 控件的 FileName 属性设置为“Powershell”,Arguments 属性如下:

String.Format(" ""& '{0}' '{1}' '{2}' '{3}' '{4}' '{5}' '{6}' '{7}' '{8}' '{9}' "" ", DeploymentScriptFileName, IO.Path.GetDirectoryName(DeploymentScriptFileName), "ExecuteBizTalkAppMSI.ps1", MSIFileName, BTDFFilename, TargetServerPath, TargetServers, ServerDeploymentFolder, InstallFolder, HostInstanceFilter, ApplicationName) 

我的问题是传递给 Powershell 的 TargetServers 参数只是 System.String[]。

从构建日志中,我可以看到 Invoke Process 控件的以下输出:

Powershell  "& 'C:\Builds\3\x.Int.MIS.Deployment\CopyDeployScriptThenExecute.ps1'
'C:\Builds\3\\x.Int.MIS.Deployment' 'ExecuteBizTalkAppMSI.ps1'
 'x.Int.MIS-3.0.0.msi' 'x.Int.MIS.Deployment.btdfproj'
'\\d-vasbiz01\BizTalkDeployment' 'System.String[]' 'c:\BizTalkDeployment'
'c:\Program Files (x86)\x.Int.MIS for BizTalk 2010\3.0' 'BTSSvc*MIS*' " 

谁能告诉我如何传递数组?

【问题讨论】:

    标签: powershell tfs tfsbuild


    【解决方案1】:

    用逗号分隔的字符串:

    PS> function foo([string[]]$x){$x}
    PS> foo a,2,3
    a
    2
    3
    

    如果需要,您可以在每个单独的项目周围加上引号,但除非它们包含空格或为语法保留的其他字符,否则您不需要这样做。

    【讨论】:

    • 感谢您回答问题的 Powershell 方面。我现在需要知道如何让 TFS 呈现以逗号分隔的数组内容。
    • string.Join(",", TargetServers.Select(s => "'"+s+"'")) 也许?
    • 我得到一个编译错误。我将不得不暂时对服务器进行硬编码,然后当我有更多时间时再回来。感谢您的尝试。
    猜你喜欢
    • 2019-12-14
    • 2013-05-06
    • 2018-11-05
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    相关资源
    最近更新 更多