步骤中处理内部构建日志

问题描述 投票:0回答:3

我想

grep
构建日志来计算编译器警告的数量。是否可以在此步骤或上一步中对构建日志运行命令?

TeamCity Enterprise 2022.04.4(内部版本 108763)

teamcity
3个回答
0
投票

您可以尝试将编译器的输出保存到文件中,然后对其进行 grep。例如

make 2>&1 | tee make.log
grep -o 'WARN' make.log | wc -l

在那种情况下

tee
将命令输出打印到标准输出和文件


0
投票

我找到了一种从 TeamCity 获取运行日志的方法。有点迂回的方式,但它有效:

warning_count=$(curl https://<teamcity-server>/downloadBuildLog.html?buildId=%teamcity.build.id% --user "%system.teamcity.auth.userId%:%system.teamcity.auth.password%" | grep -c 'warning: ')

它使用

curl
获取日志的方式与从web UI下载日志的方式相同。然后将结果输入
grep
.

附带奖励:

warning_count
可用于创建统计值:

echo "##teamcity[buildStatisticValue key='warning_count' value='$warning_count']"

0
投票

最后的答案启发我写了一些类似的东西,但使用的是 powershell。 使用此脚本运行 GNU make 后添加构建步骤:

$password = ConvertTo-SecureString "%system.teamcity.auth.password%" -AsPlainText -Force $credentials = New-Object System.Management.Automation.PsCredential("%system.teamcity.auth.userId%",$password)

告诉 Invoke-RestMethod 使用带有 Rest-API 凭据的基本身份验证方案

$response = Invoke-WebRequest -Uri "http://cad-build/httpAuth/downloadBuildLog.html?buildId=%teamcity.build.id%" -Credential $credentials

$warningCount = ([regex]::Matches -imatch ($response, "Warning" )).count 如果(!$warningCount){$warningCount = 0}

设置 TeamCity 状态/统计"

写主机 写入主机“##teamcity[buildStatus text='{build.status.text}; 生成警告:$warningCount']” 写主机“##teamcity[buildStatisticValue key='warning_count' value='$warningCount']”

© www.soinside.com 2019 - 2024. All rights reserved.