How can I Run A Sonar Analysis Without Maven?

Issue

Some project don’t build using maven but require a sonar analysis to execute against the code in the workspace.

Environment

Resolution

Sonar runner is usually executed as a maven plugin but Jenkins can invoke it without the need of maven through the Execute SonarQube Scanner task.

  1. Ensure that the SonarQube plugin for Jenkins is installed through the plugin manager

Navigate to Manage Jenkins -> Manage Plugins` and ensure that the latest version of SonarQube plugin is installed.
plugin_install.png

  1. Configure the Sonarqube server

Navigate to Manage Jenkins > Configure System > SonarQube servers and configure your sonar installation
sonarqube_server.png

  1. Configure the Sonarqube Scanner

Navigate to Manage Jenkins > Global Tool Configuration > SonarQube Scanner and add a new Sonarqube Scanner Installation
sonarqube_scanner.png

  1. Configure the job

Navigate to the job configuration and add an Execute SonarQube Scanner build step with the proper configuration.
sonarqube_job_config.png

Once configured, you should expect to see output similar to this example indicating that sonar runner is working:

...
[test] $ /Users/dvilladiego/.jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner scan -e -Dsonar.host.url=http://127.0.0.1:9000/ -Dsonar.language=java "-Dsonar.projectName=Test Java project analyzed with the SonarQube Runner" -Dsonar.projectVersion=1.0 -Dsonar.sourceEncoding=UTF-8 -Dsonar.projectKey=test-project -Dsonar.sources=src -Dsonar.projectBaseDir=/Users/dvilladiego/.jenkins/workspace/test
INFO: Option -e/--errors is no longer supported and will be ignored
INFO: Scanner configuration file: /Users/dvilladiego/.jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 2.8
INFO: Java 1.8.0_74 Oracle Corporation (64-bit)
INFO: Mac OS X 10.11.3 x86_64
INFO: User cache: /Users/dvilladiego/.sonar/cache
INFO: Load global repositories
INFO: Load global repositories (done) | time=128ms
INFO: User cache: /Users/dvilladiego/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=6ms
INFO: SonarQube server 6.2
INFO: Default locale: "es_ES", source code encoding: "UTF-8"
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=15ms
INFO: Load quality profiles
...

References:
- http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins

Have more questions? Submit a request

1 Comments

  • 0
    Avatar
    Kishore Bhatia

    Use-case: when running this Sonar Analysis build on a distributed build-node (and not the master itself) - If you see an error related to JDBC source or db connection failure, then provide additional args for jdbc source and make sure the build-node is able to connect with that jdbc source (IP/port).
    try with this additional arg (sample values shown)-
    -Dsonar.jdbc.url=jdbc:h2:tcp://sonar-vm:9092/sonar (replace with actual jdbc url)

    The sonar-runner output should reflect jdbc src arg like: C:\sonar-runner-2.4\bin\sonar-runner.bat -e -Dsonar.host.url=host:port -Dsonar.jdbc.url=jdbc:h2:tcp://host:port/sonar ...

Please sign in to leave a comment.