Executing Sonar-scanner in jenkins

I am having trouble setting the following analysis properties in jenkins to execute sonar scanner. please advice

sonar.projectKey=project12345
sonar.projectName=project_test
sonar.projectVersion=1.0
sonar.sources=/var/lib/jenkins/workspace/$JOB_NAME ------?

Hi @Osborne,

If you are using sonarqube plugin in jenkins then you don’t need to give relative path of your workspace but you can pass sonar.sources=. and it will work or you can also change according to your requirement like src. For me it was working fine this way. I hope it helps.

1 Like

Thanks Vicky, i was able to get that configured but now i am receiving a new error
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.765s
INFO: Final Memory: 9M/245M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Not authorized. Please check the properties sonar.login and sonar.password.
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
WARN: Unable to locate ‘report-task.txt’ in the workspace. Did the SonarScanner succedeed?
WARN: Unable to locate ‘report-task.txt’ in the workspace. Did the SonarScanner succedeed?
ERROR: SonarQube scanner exited with non-zero code: 1

@Osborne As it clearly mentions that you have to set the sonar username and password by
sonar.login=username
sonar.password=password

or

sonar.login=“TOKEN”

For more info you can refer https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner#AnalyzingwithSonarQubeScanner-Use this document and look into security section. Also this will help
https://docs.sonarqube.org/display/SONAR/Analysis+Parameters#AnalysisParameters-OptionalParameters
I hope it helps

1 Like

just put . or other relative path from the project root.

UPDATE:
oh, sorry, missed the first answer in topic :frowning:

sonar.projectKey=my_project
sonar.projectName=project_test
sonar.projectVersion=1.0
sonar.sources=.
sonar.language=java
sonar.sourceEncoding=UTF-8

Getting Below Error :
Unpacking https://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/3.2.0.1227/sonar-scanner-cli-3.2.0.1227.zip to /jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Sonar_Runner on f00e8c33
[Pet_Clinic_Job] $ /jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Sonar_Runner/bin/sonar-scanner Scan sonar.projectKey=my_project sonar.projectName=project_test sonar.projectVersion=1.0 sonar.sources=. sonar.language=java sonar.sourceEncoding=UTF-8 -e -Dsonar.host.url=https://uat.alm.accenture.com/sonar ******** -Dsonar.projectBaseDir=/jenkins/workspace/Raghu/Pet_Clinic_Job
ERROR: Unrecognized option: sonar.projectKey=my_project
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO: -D,–define Define property
INFO: -h,–help Display help information
INFO: -v,–version Display version information
INFO: -X,–debug Produce execution debug output
ERROR: SonarQube scanner exited with non-zero code: 1

Please suggest me :frowning :frowning: