0

I'm trying to set up the Sonar-Gerrit plugin on a Jenkin job.

Set up

  1. Jenkins Maven job is launched when a patch set to Gerrit
  2. I see the error in the Jenkins output.

Here is the Jenkins console error output :

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar ( default-cli) on project parent: Failed to execute project builder: fr.techad.sonar.GerritProjectBuilder: Failed to execute command 'gerrit review 298816ea2b24645fd971a8c0833582cec1163dac -j' on UserAtHost@55a9f72f [user=jenkins, host=172.21.33.193, port=29418]: reject HostKey: 172.21.33.193 -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

What I have tried so far

Looking the [Help 1].It says

this exception is not generated by the Maven core itself but by a plugin.

  1. I tried to log in the Jenkins server and run "mvn sonar:sonar" in the directory(/usr/share/tomcat/.jenkins/workspace/sonar-maven).It runned successfully and I could see the results on the Sonar Dashboard.
  2. Reconfigure Gerrit Trigger plugin. Then I checked the connection in the Gerrit Trigger,and it sad successful.

Did anyone have this same error? how can I try to fix it?

Software Version

  • Jenkins 2.101 , Sonar-Gerrit plugin (2.3) ,Gerrit Trigger (2.21.2)
  • Gerrit 2.14.6
  • Sonarqube 6.7
haopan
  • 11
  • 4

2 Answers2

0

The error is:

Failed to execute command 'gerrit review 298816ea2b24645fd971a8c0833582cec1163dac -j'

Sonar-gerrit uses the gerrit-trigger plugin to vote in Gerrit. It seems there is something wrong with the gerrit-trigger configuration. I know you've checked the connection between gerrit-trigger and Gerrit but this is error is related to the "gerrit review" command.

Check the "gerrit review" command at:

Jenkins > Manage Jenkins > Gerrit Trigger > Edit > Advanced... > Gerrit Verified Commands

For example, it works to me with:

gerrit review <CHANGE>,<PATCHSET> --message 'Job finished <BUILDS_STATS>' --code-review <CODE_REVIEW>

After that, if the error persists, log in the Jenkins server and run the "gerrit review" command manually executing:

ssh -p 29418 jenkins@172.21.33.193 gerrit review

If you get the same error you can try to debug it adding "-vvv" to the command.

  • Thanks,I check the commands.Such as the Successful ` gerrit review , --message 'Build Successful' --code-review ` .And I also remove "--code-verify" – haopan May 30 '18 at 03:38
  • It does not work.The same error. Is the Reject Hostkey:[Gerrit url] right?Do you have any other solution? – haopan May 30 '18 at 12:59
  • I just added more info – Marcelo Ávila de Oliveira May 30 '18 at 14:20
  • I have log in the Jenkins server **ssh -p 29418 jenkins@172.21.33.193 Gerrit review --verified +1** .It can see "Patch set 1 :Verified +1" and not error.I think the Gerrit review command is right. – haopan May 31 '18 at 03:16
  • When you say "log in the Jenkins server", are you sure you log in the machine which is executing the Maven/Sonar-gerrit job? I mean, normally the job is executed by a Jenkins slave not the Jenkins server. – Marcelo Ávila de Oliveira May 31 '18 at 17:15
  • I am sure that logging in the machine which actually excuting the job.I change the type of analyzing source.Not using with SonarQube Scanner for Jenkins, Analyzing with SonarQube Scanner is ok and not see such error .Thanks at all. – haopan Jun 03 '18 at 02:11
0

your exception says:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin

It's your maven plugin for sonar is failing the job, not the sonar-gerrit plugin.

Failed to execute command 'gerrit review 298816ea2b24645fd971a8c0833582cec1163dac -j'

I don't know what does sonarqube command "gerrit review -j" and it looks like that this sonar-maven-plugin doesn't know it, either.

You could try looking into this question - it may help you to configure sonarqube for your project: Why Maven command MVN sonar:sonar works without any plugin configuration in my POM.xml?

Tatiana Goretskaya
  • 536
  • 10
  • 25
  • This command I find in the source code (src/main/java/fr/techad/sonar/gerrit/network/ssh/GerritSshConnector.java) like "gerrit review %s -j" – haopan Jun 01 '18 at 03:09
  • Are you trying to connect Gerrit and Sonar using Maven plugin, without use of sonar-gerrit plugin that is executed by Jenkins? Then you don't need the sonar-gerrit plugin. If you want to use it, you don't need provide commands like 'gerrit review...' - you only need set up maven command "clean install sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json" in your Jenkins job settings and push a change to gerrit repository. – Tatiana Goretskaya Jun 01 '18 at 14:10
  • I changed setting the " SonarQube analysis with Maven" and the job builds successful.But using` -Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json `, I can not see any report in the Sonar Dashboard.And the Warn is > WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succedeed? – haopan Jun 03 '18 at 08:50
  • The jenkins console output says `Report has loaded and contains 242 issues Issues to be commented: 0`,but Gerrit history still says `Sonarqube violations have not been found.`@Tatiana Didik – haopan Jun 04 '18 at 10:39
  • @haopan check this out: https://stackoverflow.com/questions/48707380/sonar-gerrit-plugin-not-reporting-results/48770604#48770604 – Tatiana Goretskaya Jun 04 '18 at 14:09