Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use PyLint on Jenkins with Warnings Plugin and Pipeline

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?

like image 363
Paweł Prażak Avatar asked Jan 26 '17 14:01

Paweł Prażak


3 Answers

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 value
  • unHealthy - Report health as 0% when the number of annotations is greater than this value
  • thresholdLimit - determines which warning priorities should be considered when evaluating the build stability and health
  • defaultEncoding - the default encoding to be used when reading and parsing files
  • useDeltaValues - determines whether the absolute annotations delta or the actual annotations set difference should be used to evaluate the build stability
  • unstableTotalAll - annotation threshold
  • unstableTotalHigh - annotation threshold
  • unstableTotalNormal - annotation threshold
  • unstableTotalLow - annotation threshold
  • unstableNewAll - annotation threshold
  • unstableNewHigh - annotation threshold
  • unstableNewNormal - annotation threshold
  • unstableNewLow - annotation threshold
  • failedTotalAll - annotation threshold
  • failedTotalHigh - annotation threshold
  • failedTotalNormal - annotation threshold
  • failedTotalLow - annotation threshold
  • failedNewAll - annotation threshold
  • failedNewHigh - annotation threshold
  • failedNewNormal - annotation threshold
  • failedNewLow - annotation threshold
  • canRunOnFailed - determines whether the plug-in can run for failed builds, too
  • usePreviousBuildAsReference - determines whether to always use the previous build as the reference build
  • useStableBuildAsReference - determines whether only stable builds should be used as reference builds or not
  • canComputeNew - 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 files
  • includePattern - Ant file-set pattern of files to include in report
  • excludePattern - Ant file-set pattern of files to exclude from report
  • canResolveRelativePaths - 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 files
  • consoleParsers - the parsers to scan the console

And the parserConfigurations javadoc says only:

  • pattern - the pattern of files to parse
  • parserName - the name of the parser to use

where 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.

like image 57
Paweł Prażak Avatar answered Nov 13 '22 04:11

Paweł Prażak


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.
like image 21
javabrett Avatar answered Nov 13 '22 04:11

javabrett


For Declarative Pipeline Syntax

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

enter image description here

like image 4
Anand Tripathi Avatar answered Nov 13 '22 05:11

Anand Tripathi