2016-07-25 69 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

相關問題