gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:39:23 27 4
gpt4 key购买 nike

我正在尝试为我的 Gradle Groovy 项目生成 Codenarc 报告并在 Jenkins 中发布它们。

我成功配置了我的 Gradle 项目来生成 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")
}

config/codenarc/codenarc.groovy

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

我还在 Jenkins 上使用 Violations 插件设置了一个作业,但是当生成 Violations 报告时,它不会显示实际的代码违规情况。它只显示统计数据,如果我按违规的 groovy 文件,它会显示一个空白页。

我有带有 Codenarc 插件的 Grails 项目,该项目在违规报告中显示了完整的代码片段,所以我猜测我在 Gradle 中的 Codenarc 设置有问题?

非常欢迎任何帮助或建议!

编辑:如果相关,生成的 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>

最佳答案

考虑使用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"
]
)
}

}

关于groovy - 如何在 Jenkins 中发布 Gradle 项目的 Codenarc 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26237140/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com