Unable to set up “Sonar Gerrit” Jenkins plugin

走远了吗. 提交于 2019-12-20 04:07:23

问题


I am trying to set up Sonar Gerrit - Jenkins Plugin on a Jenkins job.

Context

  1. A Jenkins job is launched when a patch set is created to Gerrit
  2. Source are pulled with git, cppcheck analysis is launched and a sonar analysis is launched on preview mode.
  3. Post-Build action "Post SonarQube issues as Gerrit comments" is launched.

Here are the Jenkins analysis logs for the third point.

Getting Sonar Report from: [XX].sonar\sonar-report.json
Report has loaded and contains 2950 issues
Connected to Gerrit: server name: Gerrit. Change Number: 297, PatchSetNumber: 1
Unable to post review: Request failed.
Build step 'Post SonarQube issues as Gerrit comments' marked build as failure
Finished: FAILURE

A comment is added to Gerrit (meaning the communication works)

Build Failed http:jenkins.com/job/project/118/ : FAILURE

I am not able to understand where the configuration is not right. Do you know this issue ?

On Gerrit httpd_log file I have following lines when I launched a new Jenkins job.

IP - - [26/oct./2016:14:30:08 +0200] "POST /a/changes/REF/revisions/REF/review HTTP/1.1" 401 12 - "Apache-HttpClient/4.4.1 (Java/1.8.0_20)"

IP - jenkins [26/oct./2016:14:30:08 +0200] "POST /a/changes/REF/revisions/REF/review HTTP/1.1" 200 24 - "Apache-HttpClient/4.4.1 (Java/1.8.0_20)"

On first command, there is none user instead on the second one there is jenkins user. This user is used to connect Jenkins server to Gerrit server (both ssh and REST API). Is it this the issue ?


What I tried so far

Reconfigure Gerrit Trigger Plugin under Jenkins

As @Marcelo mentioned, Sonar Gerrit plugins uses Gerrit trigger. I reconfigure the entire plugin following Gerrit trigger set up.

I previously missed the step under adding Gerrit access rights for "Label Verified"

Admin > Projects > ... > Access > Edit

Reference: refs/heads/* Label : Verified: -1, +1 for Non-Interactive Users

Detailed explanation on post Can't find 'Label Verified' permission in gerrit 2.7.

Remove verified tag send from Jenkins to Gerrit As explained in install documentation for Gerrit > 2.7.

Go to "Manage Jenkins" and click the "Gerrit Trigger" link

Under "Gerrit Servers" next to your server(s) click the "Edit" button (looks like a gear, other icons may overlap it)

Under "Gerrit Reporting Values" click the Advanced button at the bottom

Under "Gerrit Verified Commands" remove the '--verified ' sections from each command


Software Version

  • Jenkins 2.19.1 Git (2.5.3), Gerrit Trigger (2.21.1), SonarQube (2.4.4), Sonnar Gerrit (1.0.6) plugins. Note: Gerrit Trigger Rest API is functional
  • SonarQube 5.5
  • Gerrit 2.12.2. Events-Log plugin installed (default configuration)

回答1:


I suspect there's a issue with your REST API connection between Jenkins and Gerrit.

The "Sonar Gerrit" plugin uses the "Gerrit Trigger" plugin to post messages in Gerrit. The "Gerrit Trigger" plugin can use two different methods to post messages in Gerrit: SSH or REST API.

The "Build Failed ... FAILURE" message is posted directly by "Gerrit Trigger" plugin and it can be performed using SSH. The "Sonar Gerrit" messages CAN'T be performed using SSH, they need to be done using REST API so the "Gerrit Trigger" plugin needs to be configured to use REST API to enable "Sonar Gerrit" plugin to post in Gerrit.

See more info here.

Go to Jenkins > Manage Jenkins > Gerrit Trigger > Edit > Advanced

And check if the REST API is enabled and if it's working as expected (using the "Test REST Connection" button)




回答2:


Does it work with section "post score?" Unchecked?

What category do you use for score posting? (Have you created it in Gerrit?)

If I remember correctly, an exception (provided by Gerrit Trigger) causing message

Unable to post review: Request failed.

is always exactly the same and doesn't help to understand the reason of RestApiException anyway.




回答3:


a new version of sonar-gerrit plugin has been released. I'm sorry for the delay.

I can't completely fix the problem JENKINS-32851 right now as reasons of the exception may vary, but I have added an ability to see the RestAPIException stacktrace. See details in the project Wiki. Please let me know if it helps (or not) and what (was?) causing your problem. I feel like I have to add some possible reasons of the exception to the troubleshooting section of the project Wiki :)



来源:https://stackoverflow.com/questions/40157708/unable-to-set-up-sonar-gerrit-jenkins-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!