Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Jenkins文件中使用Clover PHP和Checkstyle_Php_Jenkins - Fatal编程技术网

在Jenkins文件中使用Clover PHP和Checkstyle

在Jenkins文件中使用Clover PHP和Checkstyle,php,jenkins,Php,Jenkins,在我的Freestyle Jenkins工作中,我可以添加构建后操作,以使用插件生成代码覆盖率报告,并使用插件进行分析 但是,我喜欢使用管道Jenkins作业,因为它具有阶段视图。对于管道作业,我需要在Jenkins文件中设置所有内容。如何在Jenkins文件中包含Clover PHP和Checkstyle插件函数?他们的页面上没有文档。因为您想要与之集成的两个东西都有CLI接口,所以您可以使用Jenkinsfile中的sh操作调用他们的CLI来调用shell命令。以下是Clover PHP文档

在我的Freestyle Jenkins工作中,我可以添加构建后操作,以使用插件生成代码覆盖率报告,并使用插件进行分析


但是,我喜欢使用管道Jenkins作业,因为它具有阶段视图。对于管道作业,我需要在Jenkins文件中设置所有内容。如何在Jenkins文件中包含Clover PHP和Checkstyle插件函数?他们的页面上没有文档。

因为您想要与之集成的两个东西都有CLI接口,所以您可以使用
Jenkinsfile
中的
sh
操作调用他们的CLI来调用shell命令。以下是Clover PHP文档中的一个示例:

sh "phpunit --log-junit 'reports/unitreport.xml' --coverage-html 'reports/coverage' --coverage-clover 'reports/coverage/coverage.xml' test/"
Junit日志的位置将根据您在项目中放置的位置而有所不同。您必须先运行
junit
步骤,然后才能运行此步骤

检查您可以从
Jenkinsfile
中的
sh
操作以类似方式调用的样式

只要将生成的HTML文件与构建一起存档,就可以通过构建页面上的“构建工件”链接导航到生成的HTML文件来读取生成的HTML文件。示例URL结构可能如下所示:

https://ci.example.com/job/develop/342/artifact/reports/coverage/index.html

为了进行更深入的集成,这些工具可能需要显式的Jenkins管道支持。

经过多次修改后,我在管道上运行了Checkstyle,如下所示:

stage ('Static code analysis') {
    sh "sudo phpcs --config-set ignore_warnings_on_exit 1 --report=checkstyle --report-file=checkstyle-result.xml -q /code"
    step([$class: 'hudson.plugins.checkstyle.CheckStylePublisher', pattern: 'checkstyle-*'])
}
第一步生成报告,第二步调用Checkstyle插件来处理报告。我没有使用Clover PHP,因此无法帮助您。

来自Jenkins的文章是一个很好的资源

不幸的是,Clover PHP没有本机支持,但Checkstyle有:

checkstyle canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: 'build/logs/checkstyle.xml', unHealthy: ''

为了完成其他答案,Clover PHP没有jenkins管道支持。。。但是你不需要这个插件,你只需要

如果安装了一个,那么您只需在示例的Jenkins文件中添加以下内容:

step([
$class: 'CloverPublisher',
cloverReportDir: 'reports/coverage',
cloverReportFileName: 'coverage.xml',
healthyTarget: [methodCoverage: 70, conditionalCoverage: 80, statementCoverage: 80],
unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50],
failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0]])

这就是我在当前项目中使用的内容。

感谢您的快速响应。我理解这些命令,并将它们放在我的文件中。我不明白的是,Jenkins工作将如何读取生成的报告?在freestyle作业中,我可以将插件指向生成的文件,请参阅。