11
votes

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: '[email protected]',
     replyTo: '[email protected]',
     subject: 'project build successful',
     to: '[email protected]'
}

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?

4
Please edit your question and fix your styling. Your question is very hard to read. - tisto

4 Answers

7
votes

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
votes
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

5
votes

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

2
votes

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