如何在Jenkins管道中使用报告插件(PMD,PHPCPD,checkstyle,Jdepend ...)?

时间:2016-07-25 04:21:07

标签: jenkins jenkins-pipeline jenkins-2

我使用Jenkins 2.x和Jenkinsfile来运行管道。

我使用Jenkinsfile构建了一个作业,我想调用Analysis Collector插件,以便查看报告。

这是我目前的Jenkins文件:

#!groovy

node {

  stage 'Build '
    echo "My branch is: ${env.BRANCH_NAME}"
    sh 'cd gitlist-PHP && ./gradlew clean build dist'

  stage 'Report'
    step([$class: 'JUnitResultArchiver', testResults: 'gitlist-PHP/build/logs/junit.xml'])
    step([$class: 'hudson.plugins.checkstyle.CheckStylePublisher', checkstyle: 'gitlist-PHP/build/logs/phpcs.xml'])
    step([$class: 'hudson.plugins.dry.DryPublisher', CopyPasteDetector: 'gitlist-PHP/build/logs/phpcpd.xml'])

  stage 'mail'
  mail body: 'project build successful',
     from: 'siregarpandu@gmail.com',
     replyTo: 'xxxx@yyyy.com',
     subject: 'project build successful',
     to: 'siregarpandu@gmail.com'
}

我想从Jenkins调用调用Checkstyle,Junit和DRY插件。如何在Jenkinsfile中配置这些插件?这些插件是否支持管道?

4 个答案:

答案 0 :(得分:6)

以下配置适用于我:

   step([$class: 'CheckStylePublisher', pattern: 'target/scalastyle-result.xml, target/scala-2.11/scapegoat-report/scapegoat-scalastyle.xml'])

对于junit配置更容易:

junit 'target/test-reports/*.xml'

答案 1 :(得分:5)

step([$class: 'hudson.plugins.checkstyle.CheckStylePublisher', checkstyle: 'gitlist-PHP/build/logs/phpcs.xml'])

同样根据源代码repo,参数'checkstyle'应命名为'pattern'。

回购: https://github.com/jenkinsci/checkstyle-plugin/blob/master/src/main/java/hudson/plugins/checkstyle/CheckStylePublisher.java#L42

答案 2 :(得分:5)

这是我处理这个问题的方法:

<强> PMD

stage('PMD') {
    steps {
        sh 'vendor/bin/phpmd . xml build/phpmd.xml --reportfile build/logs/pmd.xml --exclude vendor/ || exit 0'
        pmd canRunOnFailed: true, pattern: 'build/logs/pmd.xml'
    }
}

<强> PHPCPD

stage('Copy paste detection') {
    steps {
        sh 'vendor/bin/phpcpd --log-pmd build/logs/pmd-cpd.xml --exclude vendor . || exit 0'
        dry canRunOnFailed: true, pattern: 'build/logs/pmd-cpd.xml'
    }
}

<强> Checkstyle的

stage('Checkstyle') {
    steps {
        sh 'vendor/bin/phpcs --report=checkstyle --report-file=`pwd`/build/logs/checkstyle.xml --standard=PSR2 --extensions=php --ignore=autoload.php --ignore=vendor/ . || exit 0'
        checkstyle pattern: 'build/logs/checkstyle.xml'
    }
}

<强> JDepend

stage('Software metrics') {
    steps {
        sh 'vendor/bin/pdepend --jdepend-xml=build/logs/jdepend.xml --jdepend-chart=build/pdepend/dependencies.svg --overview-pyramid=build/pdepend/overview-pyramid.svg --ignore=vendor .'
    }
}

您可以在此处找到完整示例:https://gist.github.com/Yuav/435f29cad03bf0006a85d31f2350f7b4

参考链接

答案 3 :(得分:1)

似乎需要修改插件以支持作为管道Steps工作,因此如果它们尚未更新,则它们不起作用。

以下是已更新的兼容插件列表:
https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md

以下是有关如何更新插件以支持管道的文档:
https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md