The Warnings Plugin already provides a Clang (LLVM based) warnings parser, but in my case I needed to set high priority to specific class of warnings. It’s a small post on how to create a custom parser for Clang warnings.
I assume the aforementioned plugin is already installed on your Jenkins. Go to Manage Jenkins > Configure System. Find the Compiler Warnings section somewhere towards the bottom, press Add to add a new parser. Here are the parameters:
1234567891011121314151617181920
Name: Clang-LLVM
Link name: Clang Compiler Warnings
Trend report name: Clang Warning Trend
Regular Expression: ^(.+?):(\d+):(?:\d+:)?(?:\{\d:-\}+)?(?:.*) (warning|error): (.*)$
Mapping Script:
import hudson.plugins.warnings.parser.Warning
import hudson.plugins.analysis.util.model.Priority
String fileName = matcher.group(1)
int lineNumber = Integer.parseInt(matcher.group(2))
String category = matcher.group(3)
String message = matcher.group(4)
Priority priority = Priority.NORMAL
if (message.contains('deprecated')) category = 'deprecation';
if (message.contains('not implemented')) priority = Priority.HIGH;
return new Warning(fileName, lineNumber, "Clang-LLVM", category, message, priority);
Example Log Message:
/Users/Shared/Jenkins/Home/jobs/project/workspace/src/AwesomeClass.m:25:17: warning: method 'theBestPlaceInTheWorld:' in protocol 'PlaceSelector' not implemented [-Wprotocol]
That’s it! You can customize it to set different categories and priorities in the lines between parsing a line and returning a new Warning object. In this case, all messages containing deprecated will have the deprecation category, and all messages mentioning not implemented will have a high priority.
Important note: the plugin de-duplicates the warnings. Since the parser is one line only (although Clang’s warnings are multiline), you can bump into a weird issue when the plugin displays fewer warnings than the Xcode generates. It happens if there is a warning in a header included from different files, in this case the actual warning in the header will be exactly the same, and the difference is in the context (above and/or below lines, which are not parsed). The plugin apparently supports multiline regular expressions, but they are quite slow, and I haven’t tried that approach. (See also: https://issues.jenkins-ci.org/browse/JENKINS-8399 and https://issues.jenkins-ci.org/browse/JENKINS-17132).