Search code examples
jenkinsjenkins-pluginssonarqube

Is it possible to run Sonar plugin on Jenkins without any build process?


I would like to run Sonar plugin on Jenkins without any build process (my intent was to integrate Sonar analysis within Jenkins and take advantage of the subversion plugins and configurations we already had on there).

I do not want to run the build process since that would take up unnecessary time; I would only like to have a Jenkins job dedicated for Sonar analysis.


Solution

  • You can do that. You have to triggering the analysis with the SonarQube Runner.

    1. Go to the Build section, click on Add build step and choose Invoke Standalone Sonar Analysis
    2. Configure the SonarQube analysis. You can either point to an existing sonar-project.properties file or set the analysis properties directly in the Project properties field

    When you analyse with SonarQube Runner , then you should give the following mandatory properties:

    sonar.projectKey=my:project
    sonar.projectName=My project
    sonar.projectVersion=1.0
    
    # Path to the parent source code directory.
    # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
    # Since SonarQube 4.2, this property is optional. If not set, SonarQube starts looking for source code
    # from the directory containing the sonar-project.properties file.
    sonar.sources=src
    

    In this case you may miss some rule violations (like FindBugs), because .class files are not provided. You have to build the project manually and set the sonar.binaries property to your class files. If you never want to build the project, then you can use the SourceMeter plugin for SonarQube too. It only needs the source files, but can produce more metrics and issues if you needed.