Ritesh Tendulkar
Ritesh Tendulkar

Reputation: 95

Sonar analysis causes 0 files indexed on a maven project through Jenkins

I am trying to integrate a standard maven project with SonarQube through Jenkins. SonarQube has been added a Post-Build Action to the project build.

I can see Sonar invoked correctly in the console output of the build, but it doesn't find any files to index. The Sonar analysis finishes successfully as far as I can tell but reports are empty.

The same command run locally from command line against a local SonarQube installation works correctly.

I've added SonarQube section in Jenkins -> Configure Jenkins section with server URL and DB URL.

The only configuration parameter on SonarQube additional properties in projects post build actions is -Dsonar.scm.disabled=true, which I believe turns off the uncommitted files check.

    [sonarcore] $ /usr/share/apache-maven/bin/mvn -f /var/lib/jenkins/workspace/sonarcore/myproject-core/pom.xml -e -B sonar:sonar -Dsonar.scm.disabled=true -Dsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?autoReconnect=true&useUnicode=true&characterEncoding=utf8 -Dsonar.host.url=http://localhost:9000/
    [INFO] Error stacktraces are turned on.
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building myproject-core 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- sonar-maven-plugin:2.5:sonar (default-cli) @ myproject-core ---
    [INFO] SonarQube version: 5.1
    INFO: Default locale: "en_US", source code encoding: "UTF-8"
    INFO: Work directory: /var/lib/jenkins/workspace/sonarcore/myproject-core/target/sonar
    INFO: SonarQube Server 5.1
    [INFO] [10:23:00.144] Load global repositories
    [INFO] [10:23:00.327] Load global repositories (done) | time=185ms
    [INFO] [10:23:00.336] Server id: 20150413092802
    [INFO] [10:23:00.338] User cache: /var/lib/jenkins/.sonar/cache
    [INFO] [10:23:00.353] Install plugins
    [INFO] [10:23:00.409] Install JDBC driver
    [INFO] [10:23:00.422] Create JDBC datasource for jdbc:mysql://localhost:3306/sonar?autoReconnect=true&useUnicode=true&characterEncoding=utf8
    [INFO] [10:23:01.722] Initializing Hibernate
    [INFO] [10:23:03.174] Load project repositories
    [INFO] [10:23:03.198] Load project repositories (done) | time=24ms
    [INFO] [10:23:03.198] Load project settings
    [INFO] [10:23:03.424] Load technical debt model
    [INFO] [10:23:03.447] Apply project exclusions
    [INFO] [10:23:03.647] -------------  Scan myproject-core
    [INFO] [10:23:03.651] Load module settings
    [INFO] [10:23:03.758] Load rules
    [INFO] [10:23:03.826] Base dir: /var/lib/jenkins/workspace/sonarcore/myproject-core
    [INFO] [10:23:03.826] Working dir: /var/lib/jenkins/workspace/sonarcore/myproject-core/target/sonar
    [INFO] [10:23:03.827] Source paths: pom.xml, src/main/java
    [INFO] [10:23:03.827] Test paths: src/test/java
    [INFO] [10:23:03.827] Binary dirs: target/classes
    [INFO] [10:23:03.828] Source encoding: UTF-8, default locale: en_US
    [INFO] [10:23:03.828] Index files
    [INFO] [10:23:03.853] 0 files indexed
    [INFO] [10:23:03.894] Sensor Lines Sensor
    [INFO] [10:23:03.895] Sensor Lines Sensor (done) | time=1ms
    [INFO] [10:23:03.896] Sensor QProfileSensor

I found another similar thread on SO that said I need to install more plugins, but I haven't been able to find which plugins do I need.

Analysing with SonarQube causes 0 files indexed and no reports (Maven Project)

I havent added SonarQube Runner on Jenkins as I don't think it is needed. Please see here https://stackoverflow.com/a/13473275/4473028

Upvotes: 1

Views: 2620

Answers (1)

Marian Costanzo
Marian Costanzo

Reputation: 23

In your server:

You need to have installed the Sonar runner on your server and you need to have the variable SONAR_RUNNER_HOME properly set.

In your jenkins configuration:

You need to set the configurations for the sonarQube Scanner like this: Sonar configuration in Global Tool Configuration

Once you install the plugin, you will be able to configure it as a step of execution in the configuration of the job.

In your job configuration:

You need to indicate the path of the sonar-project.properties file and the instance of sonnar-runner that you already configured in the step before like this: sonar step configuration

Upvotes: 0

Related Questions