douhongxie5436
2017-01-18 18:38
浏览 194
已采纳

在Jenkinsfile中使用Clover PHP和Checkstyle

Inside my Freestyle Jenkins job I can add the Post-build actions to generate a code coverage report using the plugin Clover PHP and an analysis using Checkstyle plugin.

However, I like to use the Pipeline Jenkins job, because it has the stage view. With the Pipeline job I need to set up everything inside a Jenkinsfile. How do I include the Clover PHP and Checkstyle plugin function inside a Jenkinsfile? There is no documentation on their page.

图片转代码服务由CSDN问答提供 功能建议

在我的Freestyle Jenkins工作中,我可以使用插件添加Post-build操作以生成代码覆盖率报告 Clover PHP 并使用 Checkstyle 插件。

但是,我喜欢使用管道 詹金斯的工作,因为它有舞台视图。 使用Pipeline作业,我需要在Jenkinsfile中设置所有内容。 如何在Jenkinsfile中包含Clover PHP和Checkstyle插件功能? 他们的页面上没有文档。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongmu1914 2017-01-18 19:04
    已采纳

    Since both the things you want to integrate with have CLI interfaces, you can just call their CLIs using an sh action in the Jenkinsfile to call a shell command. Here's an example from the Clover PHP docs:

    sh "phpunit --log-junit 'reports/unitreport.xml' --coverage-html 'reports/coverage' --coverage-clover 'reports/coverage/coverage.xml' test/"
    

    The location for the Junit log will vary depending on where you put in your project. You must run a junit step before this runs.

    Checkstyle also has a CLI that you can call in a similar way from an sh action in your Jenkinsfile.

    As long as you archive the resulting HTML files with your build, you can read the resulting HTML files by navigating to them through the "Build Artifacts" link on the build page. An example URL structure might look like:

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

    For deeper integration, the tools may need explicit Jenkins Pipeline support.

    点赞 评论
  • duanqing3026 2017-01-19 15:34

    After much tinkering I managed to run Checkstyle on pipeline like this:

    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-*'])
    }
    

    The first step generates the report and the second calls the Checkstyle plugin to process the report. I have not used Clover PHP so can't help you with that.

    点赞 评论
  • dongshi9526 2017-05-11 13:22

    The snippet generator from Jenkins is a great resource for this.

    Unfortunately, there's no native support for Clover PHP, but there is for Checkstyle:

    checkstyle canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: 'build/logs/checkstyle.xml', unHealthy: ''
    
    点赞 评论
  • doushe8577 2017-06-28 11:09

    To complete other answers, Clover PHP dont have jenkins pipeline support... But you dont need this plugin, all you need is the Clover Plugin

    One installed, then all you have to add in your jenkinsfile for your example, is:

    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]])
    

    This what I use in my current project.

    点赞 评论

相关推荐 更多相似问题