I want to use PyLint on Jenkins with Warnings Plugin and Pipeline, since Violations plugin is deprecated.
There are no docs or complete examples.
There is some information:
timeout(time: 5, unit: 'MINUTES') {
sh 'npm run lint:ci'
step([$class: 'WarningsPublisher',
parserConfigurations: [[
parserName: 'JSLint',
pattern: 'pmd.xml'
]],
unstableTotalAll: '0',
usePreviousBuildAsReference: true
])
}
and workarounds:
pylint || exit 0
Is there a more robust solution?
I've managed to get it working:
sh 'pylint --disable=W1202 --output-format=parseable --reports=no module > pylint.log || echo "pylint exited with $?")'
sh 'cat render/pylint.log'
step([
$class : 'WarningsPublisher',
parserConfigurations : [[
parserName: 'PYLint',
pattern : 'pylint.log'
]],
unstableTotalAll : '0',
usePreviousBuildAsReference: true
])
I'm still not sure how to configure it.
From what I was able to read from the source code and tests, those might be the possible parameters because they are the constructor parameters:
healthy
- Report health as 100% when the number of annotations is less than this valueunHealthy
- Report health as 0% when the number of annotations is greater than this valuethresholdLimit
- determines which warning priorities should be considered when evaluating the build stability and healthdefaultEncoding
- the default encoding to be used when reading and parsing filesuseDeltaValues
- determines whether the absolute annotations delta or the actual annotations set difference should be used to evaluate the build stabilityunstableTotalAll
- annotation thresholdunstableTotalHigh
- annotation thresholdunstableTotalNormal
- annotation thresholdunstableTotalLow
- annotation thresholdunstableNewAll
- annotation thresholdunstableNewHigh
- annotation thresholdunstableNewNormal
- annotation thresholdunstableNewLow
- annotation thresholdfailedTotalAll
- annotation thresholdfailedTotalHigh
- annotation thresholdfailedTotalNormal
- annotation thresholdfailedTotalLow
- annotation thresholdfailedNewAll
- annotation thresholdfailedNewHigh
- annotation thresholdfailedNewNormal
- annotation thresholdfailedNewLow
- annotation thresholdcanRunOnFailed
- determines whether the plug-in can run for failed builds, toousePreviousBuildAsReference
- determines whether to always use the previous build as the reference builduseStableBuildAsReference
- determines whether only stable builds should be used as reference builds or notcanComputeNew
- determines whether new warnings should be computed (with respect to baseline)shouldDetectModules
- determines whether module names should be derived from Maven POM or Ant build filesincludePattern
- Ant file-set pattern of files to include in reportexcludePattern
- Ant file-set pattern of files to exclude from reportcanResolveRelativePaths
- determines whether relative paths in warnings should be resolved using a time expensive operation that scans the whole workspace for matching files.parserConfigurations
- the parser configurations to scan filesconsoleParsers
- the parsers to scan the consoleAnd the parserConfigurations
javadoc says only:
pattern
- the pattern of files to parseparserName
- the name of the parser to usewhere the list of the parsers seams to be here.
If you have more information or something needs correcting feel free to edit or drop a comment.
Note that an alternative to || exit 0
or || echo "failed"
(which are fine) is to use pylint --exit-zero
:
--exit-zero Always return a 0 (non-error) status code, even if lint errors are found. This is primarily useful in continuous integration scripts.
sh 'python3 -m pylint --output-format=parseable --fail-under=<threshold value> module --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" | tee pylint.log || echo "pylint exited with $?"'
echo "linting Success, Generating Report"
recordIssues enabledForFailure: true, aggregatingResults: true, tool: pyLint(pattern: 'pylint.log')
It will break the build if the pylint rate is less then the threshold value. And using Warnings Next generation plugin it will create graphs like below
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With