Running PVS-Studio in Jenkins


Automating the analyzer run

In order to automate the analysis process in CI (Continuous Integration) you have to run the analyzer as a console application.

In Jenkins you can create one of the following build steps:

  • Execute Windows batch command
  • Windows PowerShell
  • Execute shell

and write the analysis command (and the command to convert the report in the needed format).

Examples of commands to run and integrate the analyzer into build systems are given on the following pages of documentation:

Plugin to visualize analysis results

Download the PVS-Studio Plugin on the download page in the section about Jenkins. The pvs-studio.hpi file will be saved on the disk. Jenkins plugins are distributed in such packages for manual installation.

You can install the plugin via UI by going to the menu Manage Jenkins > Manage Plugin > Advanced > Upload Plugin > Choose File, or via Jenkins CLI:

java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin SOURCE ...

PVS-Studio Plugin enables publishing static analysis results. To do this, it uses the analyzer report as an .html file, formed in the following ways:

Windows: C, C++, C#

PlogConverter.exe ... --renderTypes Html ...

Linux/macOS: C, C++

plog-converter ... --renderTypes html ... 

Windows/Linux/macOS: Java

In the settings of the plugins for Maven and Gradle in the outputType field set the html value.

To publish the analysis results in the project settings you have to add the post-build step (section Post-build Actions) Publish PVS-Studio analysis result. Mandatory field - Path to PVS-Studio analysis report, which sets the path to the .html file, the contents of which will be displayed on the build page. Relative (related to project's workspace) paths are supported. Jenkins' environment variables are also supported.

If you need to display combined results from several analyzer reports, you can combine them using the above converting utilities. Additional filtration of analysis results is available in a similar way.

After successful publishing of PVS-Studio analysis results, they will be displayed on build pages. The results of the analysis are saved for each build that allows you to view the analyzer report corresponding to a specific build.

If the resulting analyzer report is large, its preview will be displayed on the build page. The full report will be available for viewing by clicking the links View full report over / under the report preview, or Full PVS-Studio analysis report in the menu on the left.

Build page look, displaying the results of PVS-Studio analysis:

Picture 2

Warnings Next Generation Plugin

Warnings NG Plugin supports PVS-Studio analyzer reports, starting from the plugin version 6.0.0. This plugin is designed to visualize the results of various analyzers.

You can install the plugin from the standard Jenkins repository in the menu Manage Jenkins > Manage Plugins > Available > Warnings Next Generation Plugin:

Picture 5

To publish the analysis results, in project settings, you have to add the post-build step (Post-build Actions section) Record compiler warnings and static analysis results.. Next, you need to open the list Tool and choose PVS-Studio. In the Report File Pattern field you can specify the mask or the path to the analyzer report. Reports with extensions .plog and .xml.are supported.

The Report Encoding field specifies the encoding in which the report file will be read. If the field is empty, the encoding of the operation system in which Jenkins is run, will be used. Fields Custom ID and Custom Name override the identifier and the name of the chosen utility in the interface.

Here are some ways to generate a report in the needed format:

Windows: C, C++, C#

Reports with .plog extension are standard for Windows.

Linux/macOS: C, C++

plog-converter ... --renderTypes xml ... 

Windows/Linux/macOS: Java

In the settings for plugin for Maven and Gradle in the outputType field set the value xml.

After building the project a new element will appear in the PVS-Studio Warnings menu on the left. Clicking on it opens a page that visualizes data of the report created by the PVS-Studio analyzer:

Picture 7

Also, when you click on the value in the File column, the browser will open a source file on the line where the error was found. If the file doesn't open, it means that the report was generated outside the build directory or the files involved in the report have been moved or deleted.

Picture 11

In other CIs, configuration of the analyzer run and handling reports are performed in the same way.

Additional links


Bugs Found

Checked Projects
367
Collected Errors
13 552