Skip to content

stefanjames/sonarqube-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

SonarQube Deployment and Integration Guide

Step 1: Pull SonarQube Community Edition Docker Image

docker pull sonarqube

Step 2: Create Volumes

Creating volumes helps prevent the loss of information when updating or upgrading. Use the following commands:

    $ docker volume create --name sonarqube_data
    $ docker volume create --name sonarqube_logs
    $ docker volume create --name sonarqube_extensions
  

Make sure to use volumes and not bind mounts to prevent issues with plugin population.

Step 3: Run Docker Image

Use the following command to run the SonarQube image:

docker run -d --name sonarqube -p 9000:9000 -v sonarqube_data:/opt/sonarqube/data -v sonarqube_extensions:/opt/sonarqube/extensions -v sonarqube_logs:/opt/sonarqube/logs --restart=always sonarqube:community

Step 4: Access SonarQube Server

Access the SonarQube server using the default credentials (admin/admin). Change the password on initial login. Create additional users and a Token for Jenkins integration.

Step 5: Jenkins Configuration

  1. Install the SonarQube Scanner for Jenkins plugin.
  2. Create a new credential as secret text in Jenkins.
  3. Go to "Manage Jenkins" > "Configure System" and add the server URL of SonarQube with a name.
  4. Go to "Manage Jenkins" > "Global Tool Configuration" and enable SonarQube Scanners.

Step 6: Update Jenkinsfile

Update the Jenkinsfile to use the SonarQube scanner. Below is an example syntax for Maven code:


stage('sonar-scanner') {
  environment {
    SCANNER_HOME = tool 'SonarScanner'
  }
  steps {
    withCredentials([string(credentialsId: 'JenkinsToken', variable: 'sonarLogin')]) {
      sh "${SCANNER_HOME}/bin/sonar-scanner  -D sonar.host.url=http://xx.xx.xx.xx:9000 -D sonar.login=${sonarLogin}  -D sonar.projectVersion=${env.BUILD_NUMBER} -D sonar.projectKey={project.key} -D sonar.sources=./src/main/ -D sonar.tests=./src/test/ -D sonar.language=java -D sonar.java.binaries=."
    }
  }
}
  

Step 7: Access Scan Report

After the pipeline is executed, access the scan report in the SonarQube server.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published