Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the build revision number in Powershell script during TFS build

I can get the build number from IBuildDetail.BuildNumber but this is taken from the build definition and there fore might not include the revision number $(Rev:.r) or it might not be at the end.

So I would like to get this number without having to parse it from the build number. Is this property available any where during the build?

like image 501
SmudgerDan Avatar asked Apr 01 '16 16:04

SmudgerDan


2 Answers

Use the build variables.

From PowerShell use $Env:BUILD_BUILDNUMBER if you’re using TFS 2015.

See MSDN: Use a PowerShell script to customize your build process

For previous versions: Team Foundation Build environment variables

like image 116
KMoraz Avatar answered Oct 02 '22 13:10

KMoraz


you can use following powershell script to parse Build number

[String]$myrev = $Env:BUILD_BUILDNUMBER
$result = $myrev.Substring($myrev.LastIndexOf('.') + 1)
Write-Host $result 
like image 37
Reza Avatar answered Oct 02 '22 13:10

Reza