How to integrate SonarQube with Git and Teamcity


(Kiran) #1

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube Version 6.7.5 (build 38563)
  • what are you trying to achieve
    Integrate SonarQube with Git and Teamcity
  • what have you tried so far to achieve this
    Just installed Git plugin

I’m working on a POC for SonarQube enterprise edition. I currently set it up and executed the quality gate profile using the scanner on the code base which is sitting in my localhost on windows OS. I would like to integrate it with git and teamcity for CI. Can someone please help me with proper documentation and steps to set it up for CI using teamcity on git.


(Kiran) #2

My sonar-scanner.properties currently look like this:
#webclient-module.sonar.projectName=Webclient
#webclient-module.sonar.language=java
#webclient-module.sonar.sources=./webclient/components/custom/javasource
#webclient-module.sonar.java.binaries=./webclient/WebContent/WEB-INF/classes
#webclient-module.sonar.projectBaseDir=.

#ejbserver-module.sonar.projectName=EJBServer
#ejbserver-module.sonar.language=java
#ejbserver-module.sonar.sources=./EJBServer/components/custom/source
#ejbserver-module.sonar.java.binaries=./EJBServer/build/svr/cls
#ejbserver-module.sonar.projectBaseDir=.

The source code is on my local windows machine.
If I had to integrate sonarqube with git and execute sonar-scanner on source from git how would my properties file look like. Can some one help me with that.


(G Ann Campbell) #3

Hi,

We (at SonarSource) don’t maintain the TeamCity integrations, so I can only give you a general outline for how this is generally done in CIs.

Set up a job that:

  1. checks out the project
    • you’ll obviously need the relevant SCM plugin installed in your CI
  2. builds your project
    • you’ll need installed in your CI whatever build technology your project requires
  3. analyzes your project
    • if a SonarQube-related plugin is available for your CI that’s probably the easiest route
    • if no plugin is available for your CI, you’ll need to follow the normal directions making your analyzer of choice available in your CI environment.

Then run the job.

BTW, it looks rather suspicious that you have module configuration for a single project in your sonar-scanner.properties file. If that’s your analyzer of choice, you should move those configurations to your project’s local sonar-project.properties file. Also, the configurations you’ve shown in your 2nd post are all commented out, and so have no effect on the analysis regardless of which file they’re in.

 
Ann


(Kiran) #4

Thanks Ann for your reply. I know the scanner properties is commented out. But in my file they are uncommented anyways not to worry about comments. Can you please let me know how the scanner-properties file look like if I had to integrate sonarqube with git and generate a report. How to specify the sources from git?


(G Ann Campbell) #5

Hi,

Your CI job does the checkout, not analysis. There are no property adjustments to make for your SCM.

 
Ann


(Kiran) #6

Then how do I configure source for scanner and trigger scanner for sonarqube from CI?


(G Ann Campbell) #7

Hi,

Take a look at the docs: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

 
Ann


(Sam Anthonisz) #8

Hi,

I believe JetBrains provide a SonarQube plugin for TeamCity: https://confluence.jetbrains.com/display/TW/SonarQube+Integration

I haven’t used it personally (ended up rolling our own solution for TeamCity/SonarQube integration), but it may be worth investigating.

Cheers,

Sam