C code inspection using cppcheck in Jenkins

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:

  1. Automatic variable checking
  2. array bounds checking
  3. class class check
  4. Expired functions, deprecated function call checks
  5. Abnormal memory usage, free check
  6. Memory leak checking, mainly through memory reference pointers
  7. OS resource release checks, interrupts, file descriptors, etc.
  8. Exception STL function usage check
  9. 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:

Enter image description

    下载[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

Enter image description

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

Click "Build Now" to perform cppcheck analysis.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325851414&siteId=291194637