Accessing the build revision number in Powershell

2019-06-19 08:06发布

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?

2条回答
相关推荐>>
2楼-- · 2019-06-19 08:27

you can use following powershell script to parse Build number

[String]$myrev = $Env:BUILD_BUILDNUMBER
$result = $myrev.Substring($myrev.LastIndexOf('.') + 1)
Write-Host $result 
查看更多
ゆ 、 Hurt°
3楼-- · 2019-06-19 08:33

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

查看更多
登录 后发表回答