43

Learning how to use SonarQube and was doing a quick install from here

Got all the way down to step 5. My build fails when I execute: C:\sonar-runner\bin\sonar-runner.bat

I get the following error:

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 7.572s
Final Memory: 8M/223M
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.

Anyone encountered a similar situation and resolved?

SeekingAlpha
  • 7,489
  • 12
  • 35
  • 44

4 Answers4

76

If you have a java project, you must create a sonar-project.properties file in the folder where you execute sonar runner. You must define the following properties inside this file:

# Required metadata
sonar.projectKey=java-sonar-runner-simple
sonar.projectName=Simple Java project analyzed with the SonarQube Runner
sonar.projectVersion=1.0

# Comma-separated paths to directories with sources (required)
sonar.sources=src

# Language
sonar.language=java

# Encoding of the source files
sonar.sourceEncoding=UTF-8

Hope this helps,

albciff
  • 18,112
  • 4
  • 64
  • 89
  • Thanks for this. FYI: I'm using Jenkins 2.10 with Sonar Scanner 2.6.1: the paths in value `src` are relative to the Jenkins job workspace; in the job configuration, *Path to project properties* is a relative path to the file (not the folder). – groverboy Aug 09 '16 at 04:06
  • This need doesn't apply to Maven or Gradle projects – G. Ann - SonarSource Team May 26 '17 at 14:52
4

For me it was due to this: https://stackoverflow.com/a/18779516/1068411

In short: you should put sonar into "Post-Build Actions", not "Post-Build Steps".

Community
  • 1
  • 1
Sergey Evstifeev
  • 4,941
  • 2
  • 24
  • 28
  • 4
    As of SonarQube 5.x, the SonarQube documentation states using the Jenkins "Sonar" post-build action is deprecated http://docs.sonarqube.org/display/SONARNEXT/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzingwithSonarQubeScannerforMaven – asmaier Jan 25 '16 at 12:50
4

For those who has similar response on CLI and guess thy setupped everything correctly, my problem was running sonar-runner command from out side of project directory. Make sure you have cd to your project and then run the command.

Hesam
  • 52,260
  • 74
  • 224
  • 365
1

Inside Jenkins below sonar properties worked for me .

sonar.projectKey=MyWebApp
sonar.projectBaseDir=./MyWebApp
sonar.projectName=MyWebApp
sonar.projectVersion=1.0
sonar.sources=./src/main/java
sonar.language=java
sonar.java.binaries=.
##to avoid this exception Caused by: org.tmatesoft.svn.core.SVNAuthenticationException: svn: E170001
sonar.scm.disabled=True
sonar.sourceEncoding=UTF-8

Hope it will help someone.
Thanks!

Anurag_BEHS
  • 1,390
  • 2
  • 22
  • 36