2016-07-25 41 views
6

我使用Jenkins 2.x和Jenkinsfile来运行管道。如何在Jenkins管道中使用报告插件(PMD,PHPCPD,checkstyle,Jdepend ...)?

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

我想要调用从詹金斯调用的Checkstyle,JUnit和干插件。如何在Jenkinsfile中配置这些插件?这些插件是否支持管道?

+0

请编辑你的问题,并修复你的造型。你的问题很难阅读。 – tisto

回答

1

看来插件需要修改以支持Pipeline Steps,所以如果它们没有被更新,它们就不起作用。

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

这里是关于插件如何需要进行更新,以支持管道的文档:
https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md

+1

注意,它看起来不像兼容性文件是最新的,checkstyle被支持作为一般的构建步骤:步骤([$ class:'CheckStylePublisher',canComputeNew:false,defaultEncoding:'',healthy:'', pattern:'**/checkstyle-result.xml',unHealthy:''])适用于我.. – code4cause

2

下面的配置为我工作:

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

对于junit的配置更容易:

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

这是我如何处理这个问题:

PM d

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

相关问题