Jenkins and pep257 warnings

Want to get your Python pep257 docstring errors in a Jenkins job?  Then you can use the Jenkins Warnings plugin with a custom parser.  These can be added under “Manage Jenkins” > “Configure System” and in the “Compiler Warnings” section.

Add a new parser (I set “Name”, “Link name” and “Trend report name” to “pep257”) with the following settings:

Regular Expression

(.*?):(\d+)(.*)\n.*?([A-Z]\d+):(.*)

Mapping Script

import hudson.plugins.warnings.parser.Warning

String fileName = matcher.group(1);
String lineNumber = matcher.group(2);
String category = matcher.group(4);
String message = matcher.group(3) + ":" + matcher.group(5);

return new Warning(fileName, Integer.parseInt(lineNumber), "Dynamic Parser", category, message);

Example Log Message

test.py:18 in private nested class `meta`:
        D101: Docstring missing
test.py:22 in public method `method`:
        D102: Docstring missing

Jenkins job

Also worth remembering that pep257 returns an exit code of 1 if it finds any problems. This will cause the Jenkins job to be marked as failure. To avoid this change the exit code:

find . -name '*.py' | xargs pep257 || true

Leave a Reply

Your email address will not be published. Required fields are marked *