是否可以将统计值用作构建参数?

时间:2017-08-15 18:37:58

标签: teamcity

我正在添加构建功能VCS labeling。我可以在标签模式中引用statistics values吗?像

这样的东西
build-%system.build.number%-passed-%PassedTestCount%-failed-%FailedTestCount%

如果没有,我可以以某种方式传递统计值来构建参数吗?

更新

出于某种原因,REST API请求

http://teamcity:8111/httpAuth/app/rest/builds/id:$buildId/statistics/

在构建期间不返回大多数值。我不得不使用测试信息请求。这是powershell脚本:

$buildId=%teamcity.build.id%
$userId="%system.teamcity.auth.userId%"
$password="%system.teamcity.auth.password%"

$ApiCredentials_ForHeader = $userId + ":" + $password
$ApiCredentialsBase64 = [System.Convert]::ToBase64String(
    [System.Text.Encoding]::UTF8.GetBytes($ApiCredentials_ForHeader))
$ApiCredentialsHeader = @{}
$ApiCredentialsHeader.Add("Authorization", "Basic $ApiCredentialsBase64")

$testsUrl = "http://teamcity:8111/httpAuth/app/rest/testOccurrences?locator=build:(id:$buildId),count:10000"

$response = [xml](Invoke-WebRequest $testsUrl -Headers $ApiCredentialsHeader)

$PassedTestCount = @($response.testOccurrences.testOccurrence | ? { $_.status -eq "SUCCESS" }).count
$FailedTestCount = @($response.testOccurrences.testOccurrence | ? { $_.status -eq "FAILURE" }).count

Write-Host "##teamcity[setParameter name='PassedTestCount' value='$PassedTestCount']"
Write-Host "##teamcity[setParameter name='FailedTestCount' value='$FailedTestCount']"

这解决了我的问题,但没有回答问题。

1 个答案:

答案 0 :(得分:1)

如果您构建步骤之一是PowerShell(或其他类似)脚本,则可以使用TeamCity API获取统计信息。讨论了here