当前运行的TeamCity构建是否有可能检测到它是“历史记录构建”?

时间:2016-02-29 17:00:06

标签: teamcity

当前运行的TeamCity构建是否有可能通过构建参数或api调用检测到它是“历史构建”?我已经构建了通过发布NuGet包来结束的配置,如果检测到“历史记录构建”,我希望推迟发布。 TeamCity服务器似乎已经检测到这种状态,因为正在运行的构建显示为灰色。

2 个答案:

答案 0 :(得分:3)

您可以使用REST API。类似于http://MyTeamCity/app/rest/builds/BUILD_ID

要获取当前版本的BUILD_ID,请使用%teamcity.build.id%(TeamCity参数)。

该调用返回XML,其中包含有关给定构​​建的详细信息。如果是历史记录,则会有history="true"属性。

答案 1 :(得分:2)

我的团队遇到了与历史版本和nuget包类似的问题。使用sferencik的提示,我能够将以下PowerShell脚本组合在一起,该脚本作为所有构建项目的第一步运行(确保为&#34设置PowerShell运行程序选项;格式化stderr输出为"到错误)。这将导致构建在检测到历史记录构建时停止。

Write-Host "Checking for history build."

$buildUrl = "%teamcity.serverUrl%/app/rest/builds/%teamcity.build.id%"

Write-Host "URL for build data is $buildUrl"

$wc = New-Object System.Net.WebClient
$cred = New-Object System.Net.NetworkCredential("%system.teamcity.auth.userId%", "%system.teamcity.auth.password%")
$wc.Credentials = $cred

[xml]$buildXml = $wc.DownloadString($buildUrl)

$isHistory = $buildXml.build.GetAttribute("history") -eq "true"

if ($isHistory) {
    Write-Host "##teamcity[buildProblem description='This is a history build and is being abandoned.']"
    Write-Error "Build is history" 
} else {
    Write-Host "Build is not history"
}