Search code examples
teamcitycppcheck

TeamCity and cppcheck output template


I run cppcheck on my code in TeamCity and want to report its errors as build problems. So I changed the cppcheck output format to

"##teamcity[buildProblem\tdescription='{file}({line}):\t{severity}:\t{message}']"

The general idea is OK. But the problem is that some of the messages contain the character ' and this causes an error in parsing the output becasue TeamCity requires escaping apostrophes. For example, here's an excerpt from my build log:

[17:20:05][Step 2/2] Checking ..\..\..\services_package\Services\FaultsManager\FaultsManager.c...
[17:20:14][Step 2/2] ##teamcity[buildProblem    description='..\..\..\services_package\Services\FaultsManager\FaultsManager.c(83):  style:  The scope of the variable 'channelID' can be reduced.']
[17:20:15]
[Step 2/2] Property value not found
Valid property list format is (name( )*=( )*'escaped_value'( )*)* where escape symbol is "|"
[17:20:14][Step 2/2] ##teamcity[buildProblem description='..\..\..\services_package\Services\FaultsManager\CommonDef.h(32): warning:    Redundant code: Found a statement that begins with numeric constant.']

The second error gets reported but the first doesn't. I think it's becasue the first contains 'channelID' and this confuses the parser.

How can I get TeamCity to display the error messages nicely? Obviously I can get it to fail the build if the analysis fails but I want the overview page to display meaningful data - number of errors, number of new ones, the list of errors, etc. (similaly to failed tests).


Solution

  • I ended up writing a script which post-processes the output: http://blogs.microsoft.co.il/dinazil/2015/08/31/more-on-code-quality/