How to set sonar.projectBaseDir in SonarQube Scanner for Jenkins?

15,948

I found a solution, I have to add the property sonar.projectBaseDir as Analysis properties.

Configuration:

Sonar Scanner for Jenkins configuration

Log:

/Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -X -e -Dsonar.host.url=http://sonarqube:9090 -Dsonar.projectBaseDir=./../module2
Share:
15,948

Related videos on Youtube

dur
Author by

dur

Updated on June 04, 2022

Comments

  • dur
    dur almost 2 years

    I try to analyze one module of a multi module project in Jenkins with SonarQube Scanner plug-in (version 2.5). Unfortunately, Jenkins picks the wrong module as working directory.

    In this particular case, I could change the order of the modules, but in general (more than one analyzed module) it is not working. So I want to fix the problem with the property sonar.projectBaseDir, see Advanced SonarQube Scanner Usages:

    Alternate Analysis Directory

    If the files to be analyzed are not in the directory where the analysis starts from, use the sonar.projectBaseDir property to move analysis to a different directory. E.G. analysis begins from jenkins/jobs/myjob/workspace but the files to be analyzed are in ftpdrop/cobol/project1.

    sonar-project.properties

    sonar.projectBaseDir=/home/ftpdrop/cobol/project1
    sonar.sources=src
    sonar.cobol.copy.directories=/copy

    I tried following ways to set the sonar.projectBaseDir property to right module (module2 instead of module1):

    1. sonar.projectBaseDir in sonar-project.properties file

      But it doesn't work. The property in sonar-project.properties file is ignored. The log shows that the property is overriden with JVM option:

      /Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -X -e -Dsonar.host.url=http://sonarqube:9090 -Dproject.settings=/Users/test/jenkinsslave/workspace/Test/module2/sonar-project.properties -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module1
      

      I think that is a bug in SonarQube Scanner plug-in, because project.settings is incompatible with sonar.projectBaseDir, see Advanced SonarQube Scanner Usages:

      The property project.settings can be used to specify the path to the project configuration file (this option is incompatible with the project.home and sonar.projectBaseDir properties).

    2. sonar.projectBaseDir as JVM Options

      But it doesn't work. The property is ignored. The log shows that the property is overriden:

      /Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -X -e -Dsonar.host.url=http://sonarqube:9090 -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module1
      
    3. sonar.projectBaseDir as Additional arguments

      But it doesn't work. The log shows that the property is configured twice:

      /Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module2 -X -e -Dsonar.host.url=http://sonarqube:9090 -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module1
      

      I think that is a bug in SonarQube Scanner plug-in, because it should not add sonar.projectBaseDir option if there is already such option.