10

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?

KMoraz
  • 14,004
  • 3
  • 49
  • 82
SmudgerDan
  • 413
  • 5
  • 16
  • 1
    You can't get just "the revision number" without parsing -- it is not stored as a separate field somewhere. The `$(Rev:.r)` portion instructs TFS to come up with the first number that makes the build number unique (and, in that specific example, put a dot in front of it). Only the final build number is available, as KMoraz's answer suggests. – JamesQMurphy Apr 01 '16 at 22:48
  • Ok thanks for the info, was hoping not to rely on something that can be externally changed. But if it can not be done, then so be it :) – SmudgerDan Apr 05 '16 at 13:12
  • revision number may only be added at the end of the BuildNumber – or hor Feb 20 '17 at 12:51

2 Answers2

6

you can use following powershell script to parse Build number

[String]$myrev = $Env:BUILD_BUILDNUMBER
$result = $myrev.Substring($myrev.LastIndexOf('.') + 1)
Write-Host $result 
Reza
  • 414
  • 2
  • 6
  • 18
5

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

Community
  • 1
  • 1
KMoraz
  • 14,004
  • 3
  • 49
  • 82