我有一个包含两个步骤的流水线脚本。
SonarQube
分析UnitTests
如果SonarQube
发现警告,它会将它们作为评论报告给 Gerrit 并设置Code-review-1
. 下一阶段是 UnitTest,如果没问题,Pipeline 将成功,Jenkins 应向 Gerrit 报告Verified+1
。但是,当 Jenkins 报告时,Verified+1
它会删除Code-review-1
.
我的管道脚本的相关部分:
....
stage('SonarQube') {
steps {
....
....
scoreConfig: [
issueFilterConfig: [
severity: 'INFO',
newIssuesOnly: false,
changedLinesOnly: false
],
category: 'Code-Review',
noIssuesScore: 0,
issuesScore: -1
]
....
}
stage('UnitTest') {
steps {
ansiColor('xterm') {
sh '''./unittest.sh'''
}
....
我的“Gerrit 报告价值”部分:
我的 Gerrit 历史:
我的最终结果:
我的问题:
How can I set the the Code-review-1
and Verified+1
in one running? How can I avoid that Gerrit removes the Code-review-1
when reports Verified+1
? I am open to GUI solution as well as Pipeline.
EDIT:
It is not option to change the global config of Gerrit plugin. I have to solve it on Jenkins job level. Is it possible?
First of all, as I mentioned in my question the global Gerri
t config change and new Gerrit
server were not option for me. I needed to solve this problem on Jenkins job level.
I have found a "solution" which is rather a work-around, but it works.
Step 0:
如果您检查STDOUT
的SonarQube
在Jenkins
控制台日志,你可以看到这表明,它们被影响分数计算的问题数量的特定行。这一行是: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"
}
}
}
它如何工作的示例输出:
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
块以Gerrit
在UNSTABLE
构建结果的情况下报告两个值(CR 和验证标签)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句