Skip to main content
Background Image
  1. Posts/

How does SonarQube Community Edition integrate with the project

·196 words·1 min· ·
Xianpeng Shen
Author
Xianpeng Shen
Table of Contents

After you have set up the SonarQube instance, you will need to integrate SonarQube with project.

Because I used the community edition version, it doesn’t support the C/C++ project, so I only demo how to integrate with Maven, Gradle, and Others.

For example, the demo project name and ID in SonarQube are both test-demo, and I build with Jenkins.

Build with Maven
#

  1. Add the following to your pom.xml file:

    <properties>
      <sonar.projectKey>test-demo</sonar.projectKey>
    </properties>
    
  2. Add the following code to your Jenkinsfile:

    stage('SonarQube Analysis') {
      def mvn = tool 'Default Maven';
      withSonarQubeEnv() {
        sh "${mvn}/bin/mvn sonar:sonar"
      }
    }
    

Build with Gradle
#

  1. Add the following to your build.gradle file:

    plugins {
      id "org.sonarqube" version "3.3"
    }
    
    sonarqube {
      properties {
        property "sonar.projectKey", "test-demo"
      }
    }
    
  2. Add the following code to your Jenkinsfile:

    stage('SonarQube Analysis') {
      withSonarQubeEnv() {
        sh "./gradlew sonarqube"
      }
    }
    

Build with Other(for JS, TS, Python, …)
#

  1. Create a sonar-project.properties file in your repository and paste the following code:

    sonar.projectKey=test-demo
    
  2. Add the following code to your Jenkinsfile:

    stage('SonarQube Analysis') {
      def scannerHome = tool 'SonarScanner';
      withSonarQubeEnv() {
        sh "${scannerHome}/bin/sonar-scanner"
      }
    }
    

More about how to integrate with SonarQube, please visit your SonarQube instance documentation: http://localhost:9000/documentation

Related

SonarQube installation and troubleshootings
·959 words·5 mins
This article documents the steps to install SonarQube, configure LDAP, and set up PostgreSQL as the database. It also includes troubleshooting tips for common issues encountered during setup.
Run lcov failed "Can't locate JSON/PP.pm in @INC ..."
·403 words·2 mins
This article explains how to resolve the “Can’t locate JSON/PP.pm in @INC …” error when running lcov, including installing missing Perl modules.
How to fix "hidden symbol `__gcov_init' in ../libgcov.a(_gcov.o) is referenced by DSO"
·323 words·2 mins
This article explains how to resolve the “hidden symbol `__gcov_init’ in ../libgcov.a(_gcov.o) is referenced by DSO” error when building a project with Gcov, including how to ensure symbols are not hidden.
Add or update Bitbucket build status with REST API
·182 words·1 min
How to add or update the build status of a specific commit in Bitbucket using its REST API. It includes a shell script example for updating the build status and provides context on when to use this functionality.
Code coverage testing of C/C++ projects using Gcov and LCOV
·1000 words·5 mins
This article shares how to use Gcov and LCOV to metrics code coverage for C/C++ projects. It explains the steps to compile, run tests, and generate coverage reports, including example commands and expected outputs.
How to make Jenkins job fail after timeout? (Resolved)
·208 words·1 min
This article explains how to handle Jenkins job timeouts effectively by using try and catch blocks to ensure the job fails correctly when a timeout occurs.