2017-01-18 18:38

在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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongmu1914 dongmu1914 4年前

    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:

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

    点赞 评论 复制链接分享
  • dongshi9526 dongshi9526 4年前

    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 doushe8577 4年前

    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:

    $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.

    点赞 评论 复制链接分享
  • duanqing3026 duanqing3026 4年前

    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.

    点赞 评论 复制链接分享