简体   繁体   中英

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

I have a Pipeline script with two steps.

  • SonarQube analysis
  • UnitTests

If the SonarQube finds warnings, it reports them back to Gerrit as comments and set the 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 . BUT, when Jenkins reports the Verified+1 then it removes the 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 报告值部分

My Gerrit history:

格里特历史

My final result:

最后结果

My question:

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?

I think you must leave an empty string in the "Code Review" fields. The "0" value means you want to remove the previous vote. But you need also to check the global gerrit-trigger configuration at

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. 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:

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. This line is: 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:

You should check the Jenkins console log and find the number of issues which are involved in score calculation. 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 .

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:

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:

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.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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