11

我正在使用带有 a 的 Jenkins 2.xJenkinsfile来运行管道。

我已经使用 Jenkinsfile 构建了一个作业,我想调用分析收集器插件,以便查看报告。

这是我当前的 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?这些插件是否支持管道?

4

4 回答 4

7

The following configuration works for me:

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

For junit configuration is even easier:

junit 'target/test-reports/*.xml'
于 2017-01-12T16:57:46.117 回答
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'
    }
}

格纹风格

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'
    }
}

依赖

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

参考链接

于 2017-10-12T11:39:04.437 回答
5
step([$class: 'hudson.plugins.checkstyle.CheckStylePublisher', checkstyle: 'gitlist-PHP/build/logs/phpcs.xml'])

同样根据源代码仓库,参数“checkstyle”应该命名为“pattern”。

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

于 2016-09-05T04:43:24.280 回答
2

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

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

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

于 2016-08-10T13:29:07.357 回答