Accessing the build revision number in Powershell script during TFS build

不打扰是莪最后的温柔 提交于 2019-12-23 09:17:38

问题


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?


回答1:


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




回答2:


you can use following powershell script to parse Build number

[String]$myrev = $Env:BUILD_BUILDNUMBER
$result = $myrev.Substring($myrev.LastIndexOf('.') + 1)
Write-Host $result 


来源:https://stackoverflow.com/questions/36360816/accessing-the-build-revision-number-in-powershell-script-during-tfs-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!