简体   繁体   English

Jenkins Gerrit 报告值插件删除了 Code-review 的值

[英]Jenkins Gerrit reporting values plugin removes Code-review's value

I have a Pipeline script with two steps.我有一个包含两个步骤的管道脚本。

  • SonarQube analysis SonarQube分析
  • UnitTests

If the SonarQube finds warnings, it reports them back to Gerrit as comments and set the Code-review-1 .如果SonarQube发现警告,它会将它们作为注释报告回 Gerrit 并设置Code-review-1 The next stage is the UnitTest and if it is OK the Pipeline will be successful and the Jenkins should report back to Gerrit Verified+1 .下一阶段是单元测试,如果正常,管道将成功,Jenkins 应向 Gerrit Verified+1报告。 BUT, when Jenkins reports the Verified+1 then it removes the Code-review-1 .但是,当 Jenkins 报告Verified+1时,它会删除Code-review-1

Related part of my Pipeline script:我的管道脚本的相关部分:

....
    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'''
                }
      ....

My "Gerrit Reporting Values" section:我的“Gerrit 报告值”部分:

Gerrit 报告值部分

My Gerrit history:我的格里特历史:

格里特历史

My final result:我的最终结果:

最后结果

My question:我的问题:

How can I set the the Code-review-1 and Verified+1 in one running?如何在一次运行中设置Code-review-1Verified+1 How can I avoid that Gerrit removes the Code-review-1 when reports Verified+1 ?如何避免 Gerrit 在报告Verified+1时删除Code-review-1 1 ? I am open to GUI solution as well as Pipeline.我对 GUI 解决方案和 Pipeline 持开放态度。

EDIT:编辑:

It is not option to change the global config of Gerrit plugin.不能更改 Gerrit 插件的全局配置。 I have to solve it on Jenkins job level.我必须在 Jenkins 工作级别上解决它。 Is it possible?可能吗?

I think you must leave an empty string in the "Code Review" fields.我认为您必须在“代码审查”字段中留下一个空字符串。 The "0" value means you want to remove the previous vote. “0”值表示您要删除之前的投票。 But you need also to check the global gerrit-trigger configuration at但是您还需要检查全局 gerrit-trigger 配置

Jenkins > Manage Jenkins > Gerrit Trigger > Edit > Gerrit Reporting Values.

First of all, as I mentioned in my question the global Gerri t config change and new Gerrit server were not option for me.首先,正如我在问题中提到的那样,全局Gerri t 配置更改和新的Gerrit服务器不是我的选择。 I needed to solve this problem on Jenkins job level.我需要在 Jenkins 工作级别解决这个问题。

I have found a "solution" which is rather a work-around, but it works.我找到了一个“解决方案”,它是一种解决方法,但它确实有效。

Step 0:步骤 0:

If you check the STDOUT of SonarQube in the Jenkins console log, you can see a specific line which indicates the number of issues which are effected of score calculation.如果您在Jenkins控制台日志中检查SonarQubeSTDOUT ,您可以看到一个特定的行,它指示了影响分数计算的问题的数量。 This line is: Issues to be involved in score calculation: X .这一行是: Issues to be involved in score calculation: X It means you can know if there is effected issues or not based on this line.这意味着您可以根据这条线知道是否存在受影响的问题。

詹金斯控制台日志

Step 1:步骤1:

You should check the Jenkins console log and find the number of issues which are involved in score calculation.您应该检查Jenkins控制台日志并找出分数计算中涉及的问题数量。 You can see below my implementation for it.你可以在下面看到我的实现。 If there is issue (The RegEx value is not zero) then this stage should set the build result to UNSTABLE .如果存在问题( 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"
                            }
                        }
                    }

Example output of how it works:示例 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.

Step 2:第2步:

Configure the Gerrit Reporting Values block to report back the both values (CR and Verified labels) back to Gerrit in case of UNSTABLE Build result.配置Gerrit Reporting Values块以在UNSTABLE Build 结果的情况下将两个值(CR 和 Verified 标签)报告回Gerrit

在此处输入图像描述

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

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