user3097695
user3097695

Reputation: 1274

Change BuildNumber using Powershell in Teamcity

I am using Powershell script to change BuildNumber in Teamcity:

$projectFile = Resolve-Path ".\\source\\project\\project.csproj"
$info = (Get-Content $projectFile)
$matches = ([regex]'<Version>(\S*)</\Version>).Matches($info)
$newBuildNumber = $matches[0].Groups[1].Value
Write-Host "##teamcity[buildNumber '${newBuildNumber}']"

The basic idea is to use the version number in C# net core project file as build number. When this script is run, I got the following error msg.

   Unexpected token 'newBuildNumber' in expression or statement.
   [09:11:44][Step 3/8] At 
   C:\TeamCity\buildAgent\temp\buildTmp\powershell4859822141650403163.ps1:5 cha
   [09:11:44][Step 3/8] r:54
   [09:11:44][Step 3/8] + Write-Host "
   [09:11:44][Step 3/8] "
   [09:11:44][Step 3/8]     + CategoryInfo          : ParserError: 
   (newBuildNumber:String) [], ParentC 
   [09:11:44][Step 3/8]    ontainsErrorRecordException
   [09:11:44][Step 3/8]     + FullyQualifiedErrorId : UnexpectedToken

Upvotes: 0

Views: 200

Answers (1)

user6811411
user6811411

Reputation:

The regex string has no closing quote and the escaped \V causes an error.

Change to

$matches = ([regex]'<Version>(\S*)</Version>').Matches($info)

Upvotes: 1

Related Questions