Skip to content

Instantly share code, notes, and snippets.

@ghsatpute
Last active February 2, 2021 07:25
Show Gist options
  • Save ghsatpute/8a415bbce557dc94234b2e64767c56fd to your computer and use it in GitHub Desktop.
Save ghsatpute/8a415bbce557dc94234b2e64767c56fd to your computer and use it in GitHub Desktop.
Enable PR decoration on Sonar Community
  1. Install Sonar
  2. Install Community Branch Plugin
    1. Figure out compatible version of plugin with your installed sonar version
    2. Copy plugin URL from the release page
    3. Run below command at two directories /opt/sonarqube/lib/common and /opt/sonarqube/extensions/plugin (assuming your sonarqube is installed at /opt/sonarqube) wget <pluging release URL> e.g. wget https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/tag/1.3.2
    4. Restart sonar server systemctl restart sonar
    5. Access the sonar portal > Administration. You should see "Pull Request" option on left side tabs. This means plugin is installed properly.
  3. Create Github App as mentioned in this document
  4. Install above app on the repositories that you've created.
  5. Add app details in SonarQube PR plugin
    1. Administration > Configuration > General Settings
      1. On "Github" Settings
        1. Add client id, secret id from your Github App Page
        2. Add API URL. For enterprise it would be something like this https://github.company.com/api/v3
        3. Add Web URL for Github
      2. On "Pull Request" Settings
        1. Set Provider "Github"
        2. Give app id, app name, and paste the secret key created during github app creation.
  6. Manually run below command for your Java/maven project. For other project types, the parameters will be same
 mvn -X sonar:sonar \
     -Dsonar.host.url=<sonar-instance>:9000/ \
     -Dsonar.github.endpoint=<github URL> \ # Example, https://github.company.com/api/v3/ 
     -Dsonar.language=java \
     -Dsonar.jacoco.reportMissing.force.zero=true \
     -Dsonar.projectName=<Project Name> \
     -Dsonar.sourceEncoding=UTF-8 \
     -Dsonar.pullrequest.base=develop \
     -Dsonar.pullrequest.branch=SonarTest \
     -Djavax.net.debug=all \
     -Dsonar.pullrequest.key=13 \
     -Dsonar.verbose=true \
     -Dsonar.pullrequest.github.repository=<github org>/<github repo>
  1. Refer this link to automatically run this script when somebody creates the PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment