0
votes

I am having trouble running a sonar analysis on my Windows Jenkins slave using sonar-runner. The sonar server works well when analysis is done locally, and I have already resolved errors with the database connection (database connection is working for master<->slave).

  • Sonar version: 4.4
  • Jenkins version: 1.59
  • sonar-runner version: 2.4
  • Jenkins sonar plugin version: 2.1

SONAR_RUNNER_HOME\conf\sonar-runner.properties:

sonar.host.url=http://master:9000
sonar.jdbc.url=jdbc:postgresql://master/sonar
sonar.sourceEncoding=UTF-8
sonar.jdbc.username=somelogin
sonar.jdbc.password=somepassword
sonar.login=somelogin
sonar.password=somepassword
sonar.java.source=1.7

Then, sonar-runner is run from Jenkins slave (sonar properties are set in jenkins job)

[project] $ C:\jenkins\sonar-runner-2.4\bin\sonar-runner.bat -Dsonar.jdbc.driver=org.postgresql.Driver ******** ******** -Dsonar.host.url=http://master:9000 ******** ******** -Dsonar.projectBaseDir=C:\jenkins\workspace\project -Dsonar.sourceEncoding=UTF-8 -Dsonar.dynamicAnalysis=reuseReports -Dtransformer.sonar.projectBaseDir=Transform -Dsonar.language=java -Dsonar.sources=src -Dsonar.junit.reportsPath=reports -Dsonar.libraries=lib -Dsonar.jacoco.reportPath=reports/jacoco -Dsonar.binaries=build/classes -Dsonar.projectVersion=1.0 -Dsonar.modules=controller,transformer,controlpanel -Dsonar.projectKey=project -Dcontrolpanel.sonar.projectBaseDir=ModeControlPanel -Dcontroller.sonar.projectBaseDir=Controller -Dsonar.tests=test -Dsonar.projectName=project
C:\jenkins\sonar-runner-2.4
SonarQube Runner 2.4
Java 1.7.0_55 Oracle Corporation (64-bit)
Windows 7 6.1 amd64
INFO: Runner configuration file: C:\jenkins\sonar-runner-2.4\conf\sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: C:\jenkins\workspace\project\.\.sonar
INFO: SonarQube Server 4.4
13:35:00.433 INFO  - Load global settings
13:35:00.635 INFO  - User cache: C:\.sonar\cache
13:35:00.646 INFO  - Install plugins
13:35:01.017 INFO  - Install JDBC driver
13:35:01.027 INFO  - Create JDBC datasource for jdbc:postgresql://master/sonar
13:35:01.112 INFO  - Initializing Hibernate
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 4.698s
Final Memory: 11M/248M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
ERROR: 
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

What the hey!? I have defined these properties!

I apologize for multi-module example, but I promise I have tried with single module and result is the same. Ideas?

2

2 Answers

0
votes

If running sonar-runner from Jenkins on a windows slave, DO NOT include ampersands (&) in any of your password fields. My sonar.password had this character. This will cause the rest of your sonar-runner parameters to be ignored. This setting was configured in the Sonar settings, in the Jenkins system configuration.

Sorry, there was no way this could be ascertained from my question, but if anyone has this strange problem they should examine their password fields. I ended up having to edit my sonar-runner batch scripts to show the arguments, in order to find the issue.

0
votes

As is written in the log, you're missing the following properties (here filled with an example):

sonar.projectName=myproject
sonar.projectVersion=0.1-SNAPSHOT
sonar.sources=src/main/java

I always find studying the sample documentation to be useful.