How can i make the cppcheck.xml to be published on jenkins using the jenkinsfile itself?

6.5k views Asked by At

Currently I have a multibranch pipeline job where a build happens and the cppcheck is used to analyse the code. However there is no 'post build actions' tab available available in the multibranch pipeline to enable 'publish cppcheck results'. I have been searching long in the internet for an answer but i am not able to find.

There are only General,Build Triggers,Advanced project options and pipeline tabs available ( i chechked the advanced project options and there is no option to add the post build section there).

Is there a way to hardcode the cppcheck.xml publish using the jenkinsfile itself? Is there any syntax that i can use that will call the cppcheck plugin to check the xml file and publish it. This is really an emergency requirement. I tried searching a lot to convert the xml to other formats like html or jnuit xml . Nothing seems to work. Can someone help?

3

There are 3 answers

1
JamesD On

Currently the CPPCheck plugin does not support pipeline.

There is however a pull request open for the plugin

https://github.com/jenkinsci/cppcheck-plugin/pull/36

Feel free to clone it and do some more testing.

0
vincedjango On

In november 2017, the pull request mention by JamesD was merged.

If you look at the Pipeline documentation, there is now a htmlpublisher command.

Please note that the xml has to be previously generated and that the pattern argument used below search for the file from the %WORKSPACE% path.

stage('CppCheck') {
    steps {                       
        publishCppcheck pattern:'output/bin/Release/report_cppcheck.xml'
    }    
}
0
Crayon On

To do that, I'm using the Jenkins Warnings Plugin with a custom parser.

Since release 3.8 you can define new parsers dynamically in the system configuration section of Jenkins. Just navigate to http://[jenkins-url]/configure and create a new parser in section Compiler Warnings. The UI should be self explanatory

Instead of XML, a text file is generated with this command line:

cppcheck --enable=all --template="{file},{line},{severity},{id},{message}" . 2> cppcheck.txt

Here is the help for the template parameter:

--template='<text>'  Format the error messages. E.g.
                     '{file}:{line},{severity},{id},{message}' or
                     '{file}({line}):({severity}) {message}' or
                     '{callstack} {message}'
                     Pre-defined templates: gcc, vs, edit.

More information can be found in the Cppcheck PDF manual.

I'm using this regular expression to parse the file:

^(.+),(\d+),(error|warning|style|performance|portability|information),(.*),(.*)$

UPDATE

The Warnings Plugin reached end-of-life. All functionality has been integrated into the Warnings Next Generation Plugin.

With this new plugin, cppcheck is supported without the need of a custom parser.

Generate the XML file with this command line:

cppcheck --xml --xml-version=2 . 2> cppcheck.xml

In your Jenkinsfile you will need to add this line to scan the file for warnings or issues:

scanForIssues tool: cppCheck(pattern: 'cppcheck.xml')