How to use the three steps of Jenkins Warnings Next Generation Plugin properly?

18.1k views Asked by At

The Jenkins Warnings Next Generation Plugin's documentation for pipelines specifies three step variants:

  • publishIssues: Publish issues created by a static analysis scan
  • recordIssues: Record compiler warnings and static analysis results
  • scanForIssues: Scan files or the console log for warnings or issues

I've just tried this simple snippet out:

stage('QA checks') {
    steps {
        recordIssues([
            enabledForFailure: true,
            tools: [php()]
        ])
    }
}

and got the result displayed on the build's page ("PHP Runtime: No warnings"). But then what is the sense of the other two steps?

What is a proper way of configuring the plugin? Should these three parts be used, like this?

stage('QA checks') {
    steps {
        scanForIssues([...])
        recordIssues([...])
        publishIssues([...])
    }
}
2

There are 2 answers

0
user2510141 On BEST ANSWER

Came here for the same question. Figured it out from the docs. https://github.com/jenkinsci/warnings-ng-plugin/blob/master/doc/Documentation.md

In summary, the recordIssues command is intended to be used alone for simple usecases while the scanForIssues and publishIssues commands are intended to be used together for more complex usecases.

So your usage of recordIssues seems perfectly in line with the authors intent.

From the documentation:

Advanced Pipeline configuration

Sometimes publishing and reporting issues using a single step is not sufficient. E.g., if you build your product using several parallel steps and you want to combine the issues from all of these steps into a single result. Then you need to split scanning and aggregation. The plugin provides the following two steps:

  • scanForIssues: this step scans a report file or the console log with a particular parser and creates an intermediate AnnotatedReport object that contains the report. [...]
  • publishIssues: this step publishes a new report in your build that contains the aggregated results of several scanForIssues steps. [...]
0
Michael Kemmerzell On

As addition to the accepted answer maybe a bit about how to use the plugin.

The official Jenkins step documentation is also a great place to have a look on the Warnings NG plugin. The following examples are from the Warnings NG Github repo.


publishIssues: Publish issues created by a static analysis scan

publishIssues issues: [checkstyle]

recordIssues: Record compiler warnings and static analysis results

recordIssues enabledForFailure: true, aggregatingResults: true, tool: checkStyle(pattern: 'checkstyle-result.xml')

scanForIssues: Scan files or the console log for warnings or issues

scanForIssues tool: checkStyle(pattern: '**/target/checkstyle-result.xml')

The following example should show the difference between scanForIssues and publishIssues.

sh "${mvnHome}/bin/mvn --batch-mode -V -U -e checkstyle:checkstyle pmd:pmd pmd:cpd findbugs:findbugs"

def checkstyle = scanForIssues tool: checkStyle(pattern: '**/target/checkstyle-result.xml')
publishIssues issues: [checkstyle]