11

I'm using Jenkins 2.x with a Jenkinsfile to run a pipeline.

I have built a job using Jenkinsfile and I want to invoke the Analysis Collector Plugin so I can view the report.

Here is my current 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'
}

I want to invoke invoke Checkstyle, Junit and DRY plugin from Jenkins. How do I configure these plugins in the Jenkinsfile? Do these plugins support pipelines?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Pandu Siregar
  • 161
  • 2
  • 2
  • 7

4 Answers4

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'
5
step([$class: 'hudson.plugins.checkstyle.CheckStylePublisher', checkstyle: 'gitlist-PHP/build/logs/phpcs.xml'])

Also according to source code repo, the argument 'checkstyle' should be named 'pattern'.

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

Azai
  • 51
  • 2
5

This is how I handle this:

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

The full example you can find here: https://gist.github.com/Yuav/435f29cad03bf0006a85d31f2350f7b4

Reference links

Justin Wrobel
  • 1,981
  • 2
  • 23
  • 36
Marek Skiba
  • 2,124
  • 1
  • 28
  • 31
2

It appears that the plugins need to be modified to support working as Pipeline Steps, so if they have not been updated, they don't work.

Here is a list of compatible plugins that have been updated:
https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md

And here is the documentation about how the plugins need to be updated to support Pipelines:
https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md

thaddeusmt
  • 15,410
  • 9
  • 67
  • 67
  • 2
    note, it doesn't look like the compatibility file is up to date, checkstyle is supported as a general build step: step([$class: 'CheckStylePublisher', canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '**/checkstyle-result.xml', unHealthy: '']) works for me.. – code4cause Jan 10 '17 at 18:44