Issue
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
Solution
UPDATE: Per https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/ the desired functionality is now available.
What a nice way to waste an evening...
According to this Sonar Runner is not meant for Maven projects. It turns out you're supposed to look under "Post-Build Actions" (not "Post-Build Steps") and you will find "Sonar". See here for more information.
Answered By - Gili
Answer Checked By - Katrina (JavaFixing Volunteer)