Jenkins CppLint代码风格检查

准备

  • 以下平台为Ubuntu16.04
  • 已经搭建好的Jenkins+iGerrit(或Git)
  • 安装Warnings插件:Jenkins-》系统管理-》插件管理,搜索Warning安装即可。
  • CppLint.py(只需要这一个文件即可),下载地址:https://github.com/cpplint/cpplint

构建执行脚本

  • 在Jenkins的Job中,依次选择,构建 》》 执行shell脚本。添加如下代码
# 获得要检测的代码
# git clone 或者在Jenkins的源码管理中进行配置

# 假设cpplint.py放在如下路径
CPPLINT_PATH="/home/linduo/cpplint/"
# cpp文件间用空格隔开
checkFiles="xxx.cpp xxxx.cpp"

PWD_DIR=$(pwd)

# cpplint
# 检测的文件类型
CPPLINT_EXTENS=cc,cpp,h
# 过滤器定义 -就是去掉该项检查 +就是添加该项检查
CPPLINT_FITER=-whitespace/line_length,-build/include_what_you_use
# 检查代码
python $CPPLINT_PATH/cpplint.py --extensions=$CPPLINT_EXTENS --filter=$CPPLINT_FITER $checkFiles 2>&1 | tee $PWD_DIR/cpplint-result.xml
set errorlevel=0

#check result
result_cpplint=$(tail cpplint-result.xml -n 1)
result_cpplint_success="found: 0"
# 判断cpplint结果 1为成功(没有风格错误) -1为失败(有风格错误)
if [[ $result_cpplint =~ $result_cpplint_success ]]
then
	result_check=1
else
	result_check=-1
fi

# use result_check do something
  • 我这里,自己写脚本检测cpplint的结果。并将结果变量赋值,去做一些事情。对于Jenkins的Warn插件,没有设置阈值。也就是即使检测失败,也认为Job成功。

构建后用Warn扫描CPPlint结果

  • 构建后操作,选择Scan for compiler warnings,配置如下:
    Jenkins CppLint代码风格检查
  • 在右下角的高级按钮中,可以进行阈值的设置(错误数,高于阈值认为Job失败)。我这里没有配置阈值。另外,每一项都有相关的英文注释,自行阅读即可。

Jenkins系列

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2021-07-07
  • 2021-12-13
  • 2021-07-04
  • 2021-08-04
  • 2021-12-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-03-06
  • 2021-06-10
相关资源
相似解决方案