[英]Jenkins Gerrit reporting values plugin removes Code-review's value
我有一个包含两个步骤的管道脚本。
SonarQube
分析UnitTests
如果SonarQube
发现警告,它会将它们作为注释报告回 Gerrit 并设置Code-review-1
。 下一阶段是单元测试,如果正常,管道将成功,Jenkins 应向 Gerrit Verified+1
报告。 但是,当 Jenkins 报告Verified+1
时,它会删除Code-review-1
。
我的管道脚本的相关部分:
....
steps {
withSonarQubeEnv('Managed SonarQube') {
sh '''./sonar_runner.sh preview'''
sonarToGerrit(
inspectionConfig: [
serverURL: env.'SONAR_HOST_URL',
baseConfig: [
sonarReportPath: '.scannerwork/sonar-report.json',
autoMatch: true
]
],
scoreConfig: [
issueFilterConfig: [
severity: 'MINOR',
newIssuesOnly: false,
changedLinesOnly: false
],
category: 'Code-Review',
noIssuesScore: 0,
issuesScore: -1
]
)
}
stage('UnitTest') {
steps {
ansiColor('xterm') {
sh '''./unittest.sh'''
}
....
我的“Gerrit 报告值”部分:
我的格里特历史:
我的最终结果:
我的问题:
如何在一次运行中设置Code-review-1
和Verified+1
? 如何避免 Gerrit 在报告Verified+1
时删除Code-review-1
1 ? 我对 GUI 解决方案和 Pipeline 持开放态度。
编辑:
不能更改 Gerrit 插件的全局配置。 我必须在 Jenkins 工作级别上解决它。 可能吗?
我认为您必须在“代码审查”字段中留下一个空字符串。 “0”值表示您要删除之前的投票。 但是您还需要检查全局 gerrit-trigger 配置
Jenkins > Manage Jenkins > Gerrit Trigger > Edit > Gerrit Reporting Values.
首先,正如我在问题中提到的那样,全局Gerri
t 配置更改和新的Gerrit
服务器不是我的选择。 我需要在 Jenkins 工作级别解决这个问题。
我找到了一个“解决方案”,它是一种解决方法,但它确实有效。
步骤 0:
如果您在Jenkins
控制台日志中检查SonarQube
的STDOUT
,您可以看到一个特定的行,它指示了影响分数计算的问题的数量。 这一行是: Issues to be involved in score calculation: X
。 这意味着您可以根据这条线知道是否存在受影响的问题。
步骤1:
您应该检查Jenkins
控制台日志并找出分数计算中涉及的问题数量。 你可以在下面看到我的实现。 如果存在问题( RegEx
值不为零),则此阶段应将构建结果设置为UNSTABLE
。
stage('Results') {
steps {
script{
for(String line : currentBuild.getRawBuild().getLog(30)){
def find_pattern = (line =~ /^Issues to be involved in score calculation: [1-9]/)
if(find_pattern){
echo line
echo "Sonar has found warnings in changed lines. Build goes to UNSTABLE."
currentBuild.result = "UNSTABLE"
}
}
}
示例 output 的工作原理:
Report has loaded and contains 1021 issues
Issues to be commented: 1
Issues to be involved in score calculation: 1
Review has been sent
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // ansiColor
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Results)
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Issues to be involved in score calculation: 1
[Pipeline] echo
Sonar has found warnings in changed lines. Build goes to UNSTABLE.
第2步:
配置Gerrit Reporting Values
块以在UNSTABLE
Build 结果的情况下将两个值(CR 和 Verified 标签)报告回Gerrit
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.