简体   繁体   English

如何在Jenkins中发布Gradle项目的Codenarc报告?

[英]How to publish Codenarc report for Gradle project in Jenkins?

I am trying to generate Codenarc reports for my Gradle Groovy project and publish them in Jenkins. 我正在尝试为我的Gradle Groovy项目生成Codenarc报告并在Jenkins中发布它们。

I successfully configured my Gradle project to produce Codenarc reports with: 我成功配置了我的Gradle项目以生成Codenarc报告:

build.gradle 的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")
}

config/codenarc/codenarc.groovy 配置/ codenarc / codenarc.groovy

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

I also set up a job on Jenkins with the Violations plugin, but when the Violations report is generated it does not show the actual code violations. 我还使用Violations插件在Jenkins上设置了一个工作,但是当生成违规报告时,它不会显示实际的代码违规。 It just shows statistics, and a blank page if I press the groovy file with violations. 它只显示统计信息,如果我按下具有违规的groovy文件,则显示空白页面。

I have Grails projects with the Codenarc plugin, which shows up with full code snippets in the violations report, so I am guessing there is something wrong with my Codenarc setup in Gradle? 我有使用Codenarc插件的Grails项目,它在违规报告中显示完整的代码片段,所以我猜我的Gradle中的Codenarc设置有问题?

Any help or suggestions are very welcome! 非常欢迎任何帮助或建议!

Edit: If relevant, the resulting Codenarc XML looks like this: 编辑:如果相关,生成的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>

Consider using HTML Publisher plugin You can configure report parameters in job configuration Post-build Actions or if you are using pipeline, add these lines to your Jenkinsfile: 考虑使用HTML Publisher插件您可以在作业配置后构建操作中配置报表参数,或者如果您使用管道,请将这些行添加到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"
                ]
        )
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM