在PowerShell构建步骤中,在'='错误后获取缺少表达式

时间:2017-05-25 08:51:01

标签: powershell teamcity

我正在开展团队城市建设步骤。这是一个PowerShell步骤,我使用%teamcity.build.branch%和%teamcity.build.checkoutDirectory%参数。这是脚本:

param([string]$branchName=%teamcity.build.branch%, [string]$bldCheckOutDir=%teamcity.build.checkoutDir%)

write "Value of branchName is $branchName"
write "Value of bldCheckOutDir is $bldCheckOutDir"

if ($branchName.Substring(0,1) -like "F") {Write "Working on a Feature Branch"; CD $bldCheckOutDir\DCD-GUI; npm test; sonar-scanner -X}
elseif ($branchName.Substring(0,2) -like "US") {Write "Working on a Story Branch"}
elseif ($branchName.Substring(0,2) -like "DE") {Write "Working on a Defect Branch"}
elseif ($branchName.Substring(0,2) -like "QA") {Write "Working on a QA1 Branch"; CD $bldCheckOutDir\DCD-GUI; npm test; CD ..; FortifyBatchFile.bat; sonar-scanner -X; }
else {Write "BranchName not known"}

当我在构建配置中将此脚本作为构建步骤运行时,我得到以下错误:

  

[步骤4/4]工作目录:E:\ BuildAgent \ work \ d429bf6e9117eae6   [04:25:58] [步骤4/4] PowerShell论点:[ - 非交互式,   -ExecutionPolicy,ByPass,-File,E:\ BuildAgent \ temp \ buildTmp \ powershell6621137048056018482.ps1]   [04:26:08] [步骤4/4]'='后缺少表达式。 [4时26分08秒] [步骤   4/4]在   E:\ BuildAgent \ TEMP \ buildTmp \ powershell6621137048056018482.ps1:1   char:27 [04:26:08] [步骤4/4] + param([string] $ branchName =<<<< qa1,   [string] $ bldCheckOutDir = E:\ BuildAgent \ wo [04:26:08] [步骤4/4]   rk \ d429bf6e9117eae6)[04:26:08] [步骤4/4] + CategoryInfo
  :ParserError:(=:String)[],ParentContainsErrorR [04:26:08] [Step   4/4] ecordException [04:26:08] [步骤4/4] +   FullyQualifiedErrorId:MissingExpressionAfterToken

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

在参数块中,您需要将teamcity变量括在双引号或单引号中:

param(
    [string]$branchName = "%teamcity.build.branch%",
    [string]$bldCheckOutDir = "%teamcity.build.checkoutDir%"
)

如果没有它们,%字符可能会被视为特殊字符。