﻿# 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:

* [How to run PVS\-Studio on Linux and macOS](https://pvs-studio.com/en/docs/manual/0036/);
* [How to run PVS\-Studio on Windows](https://pvs-studio.com/en/docs/manual/0035/);
* [How to run PVS\-Studio Java](https://pvs-studio.com/en/docs/manual/6703/)\.

## Warnings Next Generation plugin

[Warnings NG plugin](https://plugins.jenkins.io/warnings-ng/) 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**:

![Jenkins/image1.png](https://import.viva64.com/docx/blog/Jenkins/image1.png)

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

To publish analysis results through _pipeline_ scripts, add the following:

```cpp
recordIssues enabledForFailure: true,sourceCodeEncoding:'UTF-8',
 tool: PVSStudio(pattern: 'report.plog')
```

where report\.plog is the analyzer report\.

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\+\+**

```cpp
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:

![Jenkins/image3.png](https://import.viva64.com/docx/blog/Jenkins/image3.png)

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

**Note\. **In Jenkins, to view warnings from the uploaded analyzer report in source code files \(the links in the _File _column\), the following condition must be met: when starting the _Record compiler warnings and static analysis results_ step \(the _Post\-build Actions_ section\), the project files, whose paths are specified in the analyzer report \(\*\.plog file\), should be located in the Jenkins job workspace\. The source code files to which the analyzer issued warnings are cached for each build of the Jenkins job\. So, after performing the _Record compiler warnings and static analysis results_ step \(the _Post\-build Actions_ section\), you can clear the Jenkins job workspace without losing the ability to view warnings in source code files using Jenkins\. If files do not open, then the report was created outside the Jenkins job workspace, or the cached source code files \(that were used to create the report\) in the Jenkins job build directory have been moved or deleted\.



![Jenkins/image5.png](https://import.viva64.com/docx/blog/Jenkins/image5.png)

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

## Additional links

* [Warnings NG plugin documentation \(GitHub\)](https://github.com/jenkinsci/warnings-ng-plugin/blob/master/doc/Documentation.md);
* [Running PVS\-Studio in TeamCity](https://pvs-studio.com/en/docs/manual/0049/);
* [PVS\-Studio and continuous integration](https://pvs-studio.com/en/docs/manual/0005/);
* [Integrating PVS\-Studio analysis results into SonarQube](https://pvs-studio.com/en/docs/manual/0037/)\.