user2775279
user2775279

Reputation: 13

Getting Missing expression after '=' error in powershell build step

I am working on a team city build step. This is a powershell step in which I am using %teamcity.build.branch% and %teamcity.build.checkoutDirectory% parameters. Here is the script:

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"}

When I run this script as a build step in a build configuration, I get below error:

[Step 4/4] Working directory: E:\BuildAgent\work\d429bf6e9117eae6 [04:25:58][Step 4/4] PowerShell arguments: [-NonInteractive, -ExecutionPolicy, ByPass, -File, E:\BuildAgent\temp\buildTmp\powershell6621137048056018482.ps1] [04:26:08][Step 4/4] Missing expression after '='. [04:26:08][Step 4/4] At E:\BuildAgent\temp\buildTmp\powershell6621137048056018482.ps1:1 char:27 [04:26:08][Step 4/4] + param([string]$branchName= <<<< qa1, [string]$bldCheckOutDir=E:\BuildAgent\wo [04:26:08][Step 4/4] rk\d429bf6e9117eae6) [04:26:08][Step 4/4] + CategoryInfo
: ParserError: (=:String) [], ParentContainsErrorR [04:26:08][Step 4/4] ecordException [04:26:08][Step 4/4] + FullyQualifiedErrorId : MissingExpressionAfterToken

What am I doing wrong here?

Upvotes: 1

Views: 1785

Answers (1)

Mark Wragg
Mark Wragg

Reputation: 23355

In the paramter block, you need to enclose the teamcity variables in either double or single quotes:

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

Without them the % character is likely being treated as a special character.

Upvotes: 1

Related Questions