Search code examples
jenkinssonarqubesonar-runner

Sonar + Jenkins job execution error


It's been a week since I tried to deploy this solution locally on my machine and then deploy it to a production server.
However, I faced many difficulties and incomprehension, that is what I did:

  • Sonar installation via apt-get and launch of it on port 9000 of localhost.
  • Installation of Jenkins via apt-get and launch of it on port 8080 of localhost.
  • Download the Sonar plugin for Jenkins.

After trying to running a job, it failed because :

ERROR: Error during SonarQube Scanner execution org.sonarqube.ws.client.HttpException:

The full error stack is:

ERROR: Error during SonarQube Scanner execution
org.sonarqube.ws.client.HttpException: Error 500 on http:/localhost:9000/api/ce/submit?projectKey=sonar.org:projectname&projectName=devops : {"errors":[{"msg":"An error has occurred. Please contact your administrator"}]}
    at org.sonarqube.ws.client.BaseResponse.failIfNotSuccessful(BaseResponse.java:36)
    at org.sonar.scanner.bootstrap.ScannerWsClient.failIfUnauthorized(ScannerWsClient.java:106)
    at org.sonar.scanner.bootstrap.ScannerWsClient.call(ScannerWsClient.java:75)
    at org.sonar.scanner.report.ReportPublisher.upload(ReportPublisher.java:177)
    at org.sonar.scanner.report.ReportPublisher.execute(ReportPublisher.java:131)
    at org.sonar.scanner.phases.PublishPhaseExecutor.publishReportJob(PublishPhaseExecutor.java:72)
    at org.sonar.scanner.phases.PublishPhaseExecutor.executeOnRoot(PublishPhaseExecutor.java:54)
    at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:83)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:175)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:262)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:257)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:247)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
    at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:118)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:117)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
    at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
    at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)

  http://localhost:9000/api/ce/submit?projectKey=sonar.org:projectname&projectName=devops
  : {"errors":[{"msg":"An error has occurred. Please contact your administrator"}]}

When I searched on the SonarQube logs I saw that :

2017.05.02 23:35:25 ERROR web[AVvKZ3JA+DB4lMWaAACV][o.s.s.w.WebServiceEngine] Fail to process
request http:/localhost:9000/api/qualityprofiles/restore
java.lang.IllegalStateException: Can't read file part   at
org.sonar.server.ws.ServletRequest.readPart(ServletRequest.java:102)
...
Caused by: java.io.IOException: The temporary upload location [/root/Documents/sonarqube-6.3.1/temp/tc/work/Tomcat/localhost/ROOT] is not valid

Solution

  • As seen in "The temporary upload location is not valid", make sure that the folder /root/Documents/sonarqube-6.3.1/temp/tc/work/Tomcat/localhost/ROOT

    • does exist
    • is 775 by the user running Sonar.

    Or (as seen here) you can define the temporary folder to another location

    JVM_OPTIONS="-Xrs -Xms256m -Xmx512m -Djava.io.tmpdir=/opt/another/tmp"
    

    See this thread and this thread as examples.