SonarQube scanner exited with non-zero code: 2

Hi, there
I’m a SonarQube scanner newbie.
I use Jenkins to do code analysis with sonarqube scanner.
My Jenkins was installed on vagrant machine which the virtualization provider is virtualbox. My SonarQube server is on docker container.
Here is my console output.

Started by user sherry
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/petclinic
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/petclinic/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/spring-projects/spring-petclinic.git # timeout=10
Fetching upstream changes from https://github.com/spring-projects/spring-petclinic.git
 > git --version # timeout=10
 > git --version # 'git version 2.25.1'
 > git fetch --tags --force --progress -- https://github.com/spring-projects/spring-petclinic.git +refs/pull/*:refs/remotes/origin/pr/* # timeout=10
 > git rev-parse refs/remotes/origin/main^{commit} # timeout=10
Checking out Revision 3f8468432d86dcbd0cf4372e93e06d2f47aed26a (refs/remotes/origin/main)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 3f8468432d86dcbd0cf4372e93e06d2f47aed26a # timeout=10
Commit message: "Upgrade to Boot 2.7.1"
 > git rev-list --no-walk 3f8468432d86dcbd0cf4372e93e06d2f47aed26a # timeout=10
Unpacking https://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/4.6.2.2472/sonar-scanner-cli-4.6.2.2472.zip to /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube_scanner on Jenkins
[petclinic] $ /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube_scanner/bin/sonar-scanner -Dsonar.host.url=http://10.0.2.2:9000 ******** -Dsonar.projectBaseDir=/var/lib/jenkins/workspace/petclinic
INFO: Scanner configuration file: /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube_scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.15 Private Build (64-bit)
INFO: Linux 5.4.0-122-generic amd64
INFO: User cache: /var/lib/jenkins/.sonar/cache
INFO: Scanner configuration file: /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube_scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 9.5.0.56709
INFO: Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=169ms
INFO: Server id: 32F842FD-AYIZ4UEnLdqI1p1Ipulm
INFO: User cache: /var/lib/jenkins/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=96ms
INFO: Load/download plugins (done) | time=273ms
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 3.556s
INFO: Final Memory: 8M/31M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?
ERROR: SonarQube scanner exited with non-zero code: 2
Finished: FAILURE

How can I fix this problem?
Thank you!!!

Hey there

You’ll need to define sonar.projectKey for your project. Take a look at the documentation on configuring your project.

Thank you
I fix the problem by add “-Dsonar.projectKey=your_key_name” in additional argument which is in build part of project configure.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.