C code inspection using cppcheck in Jenkins
cppcheck is a static code checking tool that supports c, c++ code; as a supplementary check to the compiler, cppcheck performs strict logic checks on the product's source code. The checks performed include:
- Automatic variable checking
- array bounds checking
- class class check
- Expired functions, deprecated function call checks
- Abnormal memory usage, free check
- Memory leak checking, mainly through memory reference pointers
- OS resource release checks, interrupts, file descriptors, etc.
- Exception STL function usage check
- Code formatting errors, and performance factor checks
Install the Cppcheck plugin in Jenkins
Log in to Jenkins with an administrator account, go to "System Management" - "Manage Plugins" - "Available Plugins", find the Cppcheck plugin in it, and select Install.
Install Cppcheck in Jenkins slave
Install cppcheck tool in each Jenkins slave
~$ sudo apt-get install cppcheck
Description: The cppcheck plugin in Jenkins is only used to process and display the cppcheck analysis results. The real analysis is the cppcheck tool on each slave
Configuration of Jenkins Job.
Take the bazel code on github as an example: [email protected] :bazelbuild/bazel.git
New Job: cppcheck_bazel
Download code:
下载[email protected]:bazelbuild/bazel.git代码的master分支,clone到${WORKSPACE}/code目录下面
Execute cppcheck for analysis:
扫描code路径下的代码,并生成cppcheck.xml扫描结果文件;将代码路径换成文件列表(test.list),可以扫描分析指定文件。
#!/bin/bash
cd ${WORKSPACE}
cppcheck -j 4 --enable=all --inconclusive --xml --xml-version=2 code 2> cppcheck.xml
#cppcheck -j 4 --enable=all --inconclusive --xml --xml-version=2 --file-list=test.list 2> cppcheck.xml
Post-build actions
In "Post-build action", select "Publish Cppcheck results" and fill in the Cppcheck report XMLs with the result file (cppcheck.xml) we generated in the build action