I'd like to grep the build log to count the number of compiler warnings. Is it possible to run a command on the build log from this or previous step?
TeamCity Enterprise 2022.04.4 (build 108763)
I'd like to grep the build log to count the number of compiler warnings. Is it possible to run a command on the build log from this or previous step?
TeamCity Enterprise 2022.04.4 (build 108763)
I found a way to get the run log from TeamCity. A bit of a roundabout way, but it works:
warning_count=$(curl https://<teamcity-server>/downloadBuildLog.html?buildId=%teamcity.build.id% --user "%system.teamcity.auth.userId%:%system.teamcity.auth.password%" | grep -c 'warning: ')
It uses curl to get the log the same way the log is downloaded from the web UI. Then just pipe the result into grep.
A side bonus: the warning_count can be used to create a Statistics value:
echo "##teamcity[buildStatisticValue key='warning_count' value='$warning_count']"
The last answer inspired me to write something alike but using powershell. Add a build step after GNU make has run with this script:
$password = ConvertTo-SecureString "%system.teamcity.auth.password%" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PsCredential("%system.teamcity.auth.userId%",$password)
# Tell Invoke-RestMethod to use Basic Authentication scheme with Rest-API credentials
$response = Invoke-WebRequest -Uri "http://<host_url>/httpAuth/downloadBuildLog.html?buildId=%teamcity.build.id%" -Credential $credentials
$warningCount = ([regex]::Matches($response, "(?i)warning" )).count
# Set TeamCity status/statistic"
Write-Host
Write-Host "##teamcity[buildStatus text='{build.status.text}; Build warnings: $warningCount']"
Write-Host "##teamcity[buildStatisticValue key='warning_count' value='$warningCount']"