如何在Jenkins流水线中使用(PMD、PHPCPD、checkstyle、Jdepend等)的报告插件?

11

我正在使用Jenkins 2.x,通过Jenkinsfile运行流水线。

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

这是我的当前Jenkinsfile:

#!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中配置这些插件?这些插件支持流水线吗?


请编辑您的问题并修复样式。您的问题很难阅读。 - tisto
4个回答

7
以下配置对我有效:

以下配置对我有效:

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

对于JUnit配置,甚至更加简单:

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

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
参考链接:
https://jenkins.io/doc/pipeline/steps/

5

2

2
注意,兼容性文件似乎不是最新的,请检查。Checkstyle作为一般构建步骤得到支持:step([$class: 'CheckStylePublisher', canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '**/checkstyle-result.xml', unHealthy: '']) 对我来说有效。 - code4cause

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接