0

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)

1
  • you could try call TeamCity REST API from bash script to get current build status Commented Jan 31, 2023 at 15:15

3 Answers 3

1

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']"
Sign up to request clarification or add additional context in comments.

Comments

1

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']"

Comments

0

You could try to save compiler's output to a file and then grep it. For example

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

In that case tee prints command output to both stdout and file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.