将构建过程参数传递给Powershell脚本

时间:2014-08-25 20:38:26

标签: powershell tfs tfs2013

所以我定义了一个流程模板,它在我的Build Definition中接受一个名为BuildDefinitionList的String数组。然后我调用一个powershell脚本。我想要做的是检索String类型的数组。如何从我的PowerShell脚本中实现这一目标?

更新

我已经修改了流程模板,使其具有带脚本路径参数和脚本参数参数的InvokeProcess活动。为了自定义我的定义,我已将以下内容用作指导here

我有一个名为Script的流程参数,它具有powershell脚本的路径 我有另一个名为ScriptArguments的进程参数,它具有以下内容。

builds `"Test 1`", `"Test 2`", `"Test 3`", `"Test 4`"

我的脚本接受或正在寻找一个String数组

[cmdletbinding()]
Param(
    [Parameter(Mandatory=$false,
                       ValueFromPipeline=$true,          
             ValueFromPipelineByPropertyName=$true)]
    $builds
)

当我运行构建时,出现以下错误

A positional parameter cannot be found that accepts
 argument 'Test 1'.

1 个答案:

答案 0 :(得分:-1)

您可以创建一个参数,并为其指定[String[]]的类型。

Param(
[String[]]$SomeStrings
)
ForEach($String in $SomeStrings){
    Do stuff!
}

然后在调用时将数组传递给脚本。

相关问题