I added a build step to execute a Python script.
In this script pylint is called with the lint.Run(..args) to check the code.
The script works but in the end, the bu
I agree with @dmeister, but with pipeline code (Jenkinsfile) I suggest a try/catch and then parsing the error. This way you can determine if you're just getting status bits from pylint (see the Pylint docs), whether pylint reports a usage error, or whether there was a catastrophic fail:
try {
sh 'pylint --output-format=parseable my_module'
} catch ( pylint_rc ) {
// pylint_rc will be of the form
// "hudson.AbortException: script returned exit code NN"
// where NN is 1-63 and represents bit field;
// bits 0-4 indicate lint-ish issues in analyzed code,
// bit 5 indicates pylint usage error
echo "pylint_rc= \'$pylint_rc\'"
String rc = "$pylint_rc"
String code = rc.split()[5]
echo "Isolated return code string value $code"
int value = code.toInteger()
// catastrophic/crash error returns a 1; else there is a pylint return code
int error_bits_code = value & 0x20
int lint_bits_code = value & 0x1f
echo "pylint error_bits_code=$error_bits_code ; lint_bits_code=$lint_bits_code"
if ( (value == 1) || (error_bits_code != 0) ) {
currentBuild.result = "FAILURE"
throw pylint_rc
}
}
Apologies to groovy purists - groovy isn't my thing, so I'm sure this can be improved on - let me know. There is one known hole: if pylint detects only "fatal"-type errors (bit 0) and no other issues of any kind (bits 1-4 are not set) then this code will incorrectly throw an exception. But my code flags tons of issues, so that's not a problem for me. The fix (?parse error msg?) might be trivial for someone with groovy chops.
You can also simply put a
pylint || exit 0
in the shell cmdline. The Pylint plugin will fail the build anyway by checking the result of pyllint.
Pylint expect the code being analyzed to be 100% perfect. Even code warning may cause exit with non zero status code. Try to fix your code as Pylint suggest and rate 10/10.
Hope this helps.
it seems that your pylint execution exit with a non-zero status (missing script, bad options...), maybe you exit the script with an exception raised or a sys.exit(something_else_than_zero)
Recent rylint have option for not calling sys exit
lint.Run(args, exit=False, **kwargs)
In Pylint 1.9.3, there is a --exit-zero
flag.
https://github.com/PyCQA/pylint/blob/1.9/ChangeLog#L47