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 # timeout=10
Fetching upstream changes from
 > git --version # timeout=10
 > git --version # 'git version 2.25.1'
 > git fetch --tags --force --progress -- +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 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.projectBaseDir=/var/lib/jenkins/workspace/petclinic
INFO: Scanner configuration file: /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube_scanner/conf/
INFO: Project root configuration file: NONE
INFO: SonarScanner
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/
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server
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: ------------------------------------------------------------------------
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: 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.