TFS 2018 XAML 构建迁移
TFS 2018 XAML build migration
我目前正在将我们的 XAML 构建定义升级到新的构建系统。已经消除了一些错误,但现在我无法再判断可能出了什么问题。我们在大部分构建过程中使用 PowerShell 脚本,尽管服务器上提供了所有必需的数据,但在 运行 构建时出现以下错误:
有谁知道是什么导致了这个错误?或者至少我应该检查哪里?
提前致谢。
编辑:
该脚本准备了外部工具无法完成且特定于我们项目的构建配置。错误发生在 $teamProjectCollection =...
行
Function Get-BuildNumberFromUri() {
<#
.SYNOPSIS
Reads the build number from the current TFS build ($Env:BUILD_BUILDURI)
.DESCRIPTION
Reads the build number from the current TFS build ($Env:BUILD_BUILDURI)
.NOTES
May fail if $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI or $env:BUILD_BUILDURI
are not set
#>
[String] $CollectionUrl = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"
[String] $BuildUrl = "$env:BUILD_BUILDURI"
if (-not $CollectionUrl -or -not $BuildUrl) {
return "0"
}
[void[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($CollectionUrl)
$buildServer = $teamProjectCollection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDetail = $buildServer.GetBuild($BuildUrl)
$buildNumber = $buildDetail.BuildNumber
return $buildNumber
}
在以前版本的 Team Foundation Server 中,客户端对象模型在 运行 XAML 时在 GAC 中注册并由构建代理预加载。在新代理中,构建步骤独立于客户端对象模型。
您有两种选择来定位客户端对象模型程序集:
- 通过引用客户端对象模型 Nuget 包,使用 powershell 脚本发送客户端对象模型。
- Detect the location where Visual Studio is installed and loading the client object model from the Team Explorer extension folder. Examples can be found on the docs wiki.
还有一个更简单但官方不支持的选项:
Do not use $(Agent.ServerOMDirectory). It is not safe for task authors to depend on the SDK bundled with the agent. Agent.ServerOMDirectory is a convenience variable that points to the latest SDK bundled with the agent. The SDK may have breaking interface changes between different versions. Depending on the latest version shipped with the agent will cause your task to be unreliable.
获取版本号
正在填充构建变量以在您的脚本中设置构建号,可以使用 $env:Build.BuildNumber
引用它。
要设置内部版本号,请使用
向控制台写入一条特殊语句
$value = "$($env:Build.BuildNumber)_US`
Write-Host "##vso[build.updatebuildnumber]$Value"
或者,您可以使用 VSTS Variable Toolbox extension.
中我的 设置变量 任务
这是问题所在:
您正在使用新的构建系统。您需要退后一步,根据新构建系统的功能重新评估现有脚本。
您有这个检索内部版本号的大型 PowerShell 代码段。太棒了,除了两件事:
- 它永远不会起作用 -- SOAP 对象模型不了解 "new"(例如非 XAML)构建。相反,有一个 REST API。
- 您可以通过查看
$env:BUILD_BUILDNUMBER
变量来检索当前内部版本号。无需特殊代码。
我目前正在将我们的 XAML 构建定义升级到新的构建系统。已经消除了一些错误,但现在我无法再判断可能出了什么问题。我们在大部分构建过程中使用 PowerShell 脚本,尽管服务器上提供了所有必需的数据,但在 运行 构建时出现以下错误:
有谁知道是什么导致了这个错误?或者至少我应该检查哪里?
提前致谢。
编辑:
该脚本准备了外部工具无法完成且特定于我们项目的构建配置。错误发生在 $teamProjectCollection =...
Function Get-BuildNumberFromUri() {
<#
.SYNOPSIS
Reads the build number from the current TFS build ($Env:BUILD_BUILDURI)
.DESCRIPTION
Reads the build number from the current TFS build ($Env:BUILD_BUILDURI)
.NOTES
May fail if $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI or $env:BUILD_BUILDURI
are not set
#>
[String] $CollectionUrl = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"
[String] $BuildUrl = "$env:BUILD_BUILDURI"
if (-not $CollectionUrl -or -not $BuildUrl) {
return "0"
}
[void[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($CollectionUrl)
$buildServer = $teamProjectCollection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDetail = $buildServer.GetBuild($BuildUrl)
$buildNumber = $buildDetail.BuildNumber
return $buildNumber
}
在以前版本的 Team Foundation Server 中,客户端对象模型在 运行 XAML 时在 GAC 中注册并由构建代理预加载。在新代理中,构建步骤独立于客户端对象模型。
您有两种选择来定位客户端对象模型程序集:
- 通过引用客户端对象模型 Nuget 包,使用 powershell 脚本发送客户端对象模型。
- Detect the location where Visual Studio is installed and loading the client object model from the Team Explorer extension folder. Examples can be found on the docs wiki.
还有一个更简单但官方不支持的选项:
Do not use $(Agent.ServerOMDirectory). It is not safe for task authors to depend on the SDK bundled with the agent. Agent.ServerOMDirectory is a convenience variable that points to the latest SDK bundled with the agent. The SDK may have breaking interface changes between different versions. Depending on the latest version shipped with the agent will cause your task to be unreliable.
获取版本号
正在填充构建变量以在您的脚本中设置构建号,可以使用 $env:Build.BuildNumber
引用它。
要设置内部版本号,请使用
向控制台写入一条特殊语句$value = "$($env:Build.BuildNumber)_US`
Write-Host "##vso[build.updatebuildnumber]$Value"
或者,您可以使用 VSTS Variable Toolbox extension.
中我的 设置变量 任务这是问题所在:
您正在使用新的构建系统。您需要退后一步,根据新构建系统的功能重新评估现有脚本。
您有这个检索内部版本号的大型 PowerShell 代码段。太棒了,除了两件事:
- 它永远不会起作用 -- SOAP 对象模型不了解 "new"(例如非 XAML)构建。相反,有一个 REST API。
- 您可以通过查看
$env:BUILD_BUILDNUMBER
变量来检索当前内部版本号。无需特殊代码。