2014-10-07 48 views
4

我想爲我的Gradle Groovy項目生成Codenarc報告並在Jenkins中發佈它們。如何發佈Jenkins中的Gradle項目的Codenarc報告?

我成功地配置我的搖籃項目產生Codenarc與報道:

的build.gradle

apply plugin: 'codenarc' 
... 
dependencies { 
    codenarc 'org.codenarc:CodeNarc:0.21' 
    ... 
} 
codenarc { 
    configFile = file('config/codenarc/codenarc.groovy') 
    // sourceSets = [project.sourceSets.main] // run codenarc on production sources only 
    ignoreFailures = true // Let the build finish even though there are code warnings 
    reportFormat = 'xml' 
    reportsDir = new File("build/reports/codenarc") 
} 

配置/ codenarc/codenarc.groovy

// Read and choose rules here: http://codenarc.sourceforge.net/codenarc-rule-index.html 
ruleset { 
    ruleset('rulesets/basic.xml') 
} 

我也用Violations插件在Jenkins上創建一份工作,但是當Violations報告屬於一般情況時它不顯示實際的代碼違規。它只顯示統計信息,如果我按違規的groovy文件,則顯示一個空白頁面。

我有Codenarc插件的Grails項目,它在違規報告中顯示了完整的代碼片段,所以我猜測我的Codenarc安裝程序在Gradle中出現了問題?

任何幫助或建議都非常歡迎!

編輯: 如果相關,所產生的Codenarc XML是這樣的:

<?xml version='1.0'?> 
<CodeNarc url='http://www.codenarc.org' version='0.21'> 
    <Report timestamp='07-10-2014 15:31:18'/> 
    <Project title=''> 
     <SourceDirectory>src\groovy</SourceDirectory> 
    </Project> 
    <PackageSummary totalFiles='124' filesWithViolations='118' priority1='0' priority2='156' 
        priority3='143'></PackageSummary> 
    <Package path='testmodel' totalFiles='124' filesWithViolations='118' priority1='0' priority2='156' 
      priority3='143'></Package> 
    <Package path='testmodel/begivenheder' totalFiles='31' filesWithViolations='30' priority1='0' priority2='32' 
      priority3='17'> 
     <File name='AbstraktTest.groovy'> 
      <Violation ruleName='ClassJavadoc' priority='2' lineNumber='5'> 
       <SourceLine><![CDATA[@CompileStatic]]></SourceLine> 
       <Message><![CDATA[Class testmodel.begivenheder.AbstraktAendring missing JavaDoc]]></Message> 
      </Violation> 
      ... 
     </File> 
    </Package> 
    <Rules> 
     <Rule name='AbcMetric'> 
      <Description> 
       <![CDATA[Checks the ABC size metric for methods/classes. A method (or "closure field") with an ABC score greater than the maxMethodAbcScore property (60) causes a violation. Likewise, a class that has an (average method) ABC score greater than the maxClassAverageMethodAbcScore property (60) causes a violation.]]></Description> 
     </Rule> 
     ... 
    </Rules> 
</CodeNarc> 
+0

是否有任何示例項目可供嘗試? – Opal 2014-10-17 08:45:21

+0

也許它與這個開放的詹金斯問題有關? https://issues.jenkins-ci.org/browse/JENKINS-17722。症狀似乎相同。 – 2014-10-22 20:10:01

回答

0

考慮使用HTML Publisher plugin 可以在作業配置配置報表參數生成後操作或者如果您使用的管道,將這些行添加到Jenkinsfile中:

node('slaveName') { 

    // git, build, test, stages omitted 

    stage('Publish') { 

     echo 'Publish Codenarc report' 
     publishHTML(
       target: [ 
         allowMissing   : false, 
         alwaysLinkToLastBuild: false, 
         keepAll    : true, 
         reportDir   : 'target/site', 
         reportFiles   : 'codenarc.html', 
         reportName   : "Codenarc Report" 
       ] 
     ) 
    } 

}