Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarRunner can't find sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources

I am attempting to get Jenkins to run Sonar as a post-build step.

Jenkins runs SonarRunner [1] but this fails with:

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

If I run mvn sonar:sonar [2] instead it works fine. It almost sounds like SonarRunner is ignoring pom.xml. How do I get SonarRunner to pick up these properties from Maven?


[1] /Users/builds/.jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Default_Sonar_Runner/bin/sonar-runner -Dsonar.jdbc.url=jdbc:h2:tcp://myServer:1009/sonar -Dsonar.host.url=http://myServer/sonar/ -Dsonar.projectBaseDir=/Users/builds/.jenkins/workspace/myProject

[2] mvn sonar:sonar -Dsonar.jdbc.url=jdbc:h2:tcp://myServer:1009/sonar -Dsonar.host.url=http://myServer/sonar/ -Dsonar.projectBaseDir=/Users/builds/.jenkins/workspace/myProject

like image 579
Gili Avatar asked Sep 13 '13 06:09

Gili


People also ask

What is Sonar projectKey?

projectKey is simply the unique identifier of your project inside SonarQube. You are free to choose whatever you want, as long as it is unique. Analysis Parameters is the official documentation page from Sonar, where you can find additional information about all the properties.

How do I set sonar project properties?

SonarQube Properties and Parameters Global analysis parameters, defined in the UI, apply to all the projects (From the top bar, go to Settings > General Settings) Project analysis parameters, defined in the UI, override global parameters (At a project level, go to Configuration > Settings)


1 Answers

Method 1: If you installed a scanner in Jenkins then just add the following in this location on your job
Post Steps -> Execute SonarQube Scanner -> Analysis properties

sonar.projectKey=myProject1
sonar.sources=.

Method 2: Another alternative is using the deprecated method which still works fine Post-build Actions -> SonarQube analysis with Maven

Method 3: Build -> Goals and options -> "enter the below script" -Dmaven.test.skip=true install sonar:sonar -Dsonar.forceAnalysis=true -Dsonar.host.url=http://localhost:9000/ -Dsonar.branch=my-branch-1

like image 175
electricalbah Avatar answered Nov 15 '22 23:11

electricalbah