web-dev-qa-db-ja.com

Jenkinsパイプラインの(PMD、PHPCPD、checkstyle、Jdepend ...)でレポートプラグインを使用するにはどうすればよいですか?

Jenkins2.xとJenkinsfileを使用してパイプラインを実行しています。

Jenkinsfileを使用してジョブを作成しましたが、レポートを表示できるようにAnalysisCollectorプラグインを呼び出したいと思います。

これが私の現在の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: '[email protected]',
     replyTo: '[email protected]',
     subject: 'project build successful',
     to: '[email protected]'
}

JenkinsからinvokeCheckstyle、Junit、DRYプラグインを呼び出したい。これらのプラグインをJenkinsfileで構成するにはどうすればよいですか?これらのプラグインはパイプラインをサポートしていますか?

10
Pandu Siregar

次の構成が機能します。

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

JUnitの構成はさらに簡単です。

junit 'target/test-reports/*.xml'
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

5
Azai

これは私がこれを処理する方法です:

[〜#〜] 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

参照リンク

5
Marek Skiba

プラグインはパイプラインとして機能するように変更する必要があるようです ステップ したがって、プラグインが更新されていない場合、プラグインは機能しません。

更新された互換性のあるプラグインのリストは次のとおりです。
https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md

そして、パイプラインをサポートするためにプラグインを更新する必要がある方法に関するドキュメントは次のとおりです。
https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md

2
thaddeusmt