jenkins + sonar + github integration jenkins + sonar + github integration jenkins jenkins

jenkins + sonar + github integration


Finally I am able to solve this issue. Here is the detail:

  1. Install Sonar with GitHub plugin.
  2. Install Jenkins with the following plugins

    • GitHub Pull Request Builder
    • SonarQube Plugin
    • GIT plugin
    • GitHub plugin

Follow this link to setup pull request builder plugin: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-EnvironmentVariables

    1. Global Jenkins System Setup:
  • Goto Manage Jenkins -> Configure System
  • Configure jdkenter image description here
  • Install sonarQube Runnerenter image description here
  • Configure Sonarenter image description here
  • Git WebHook Setupenter image description here
  • PullRequest Builder Setupenter image description here

    1. Create Free Style Jenkins jobenter image description here
  • add github url to GitHub Project sectionenter image description here

  • Setup Source Code Management Sectionenter image description here

  • Setup Build Trigger enter image description here

  • Setup Sonar for post build actionsenter image description here

  • In the additional properties section provide the following sonar properties

-Dsonar.sourceEncoding=UTF-8 -Dsonar.analysis.mode=preview -Dsonar.github.repository=company/repo-Dsonar.github.login=gitusername -Dsonar.github.oauth=oauthtoken-Dsonar.host.url=sonarhostedurl-Dsonar.login=admin -Dsonar.password=pass-Dsonar.github.pullRequest=${ghprbPullId}${ghprbPullId}: this will be provided via github pullrequest builder plugin

Note: The job should be triggered through pullrequest builder plugin otherwise ${ghprbPullId} will return blank. If you run the job manually this will not work for that you have to pass this ${ghprbPullId} property as a build parameter. If you want to check the environment parameter available follow this Git environment variables for use in executing Jenkins shell scripts

I hope this helps.


Too long for a comment so I'll have to write it here.

After some research on the web I've found a question on SO from someone a few steps ahead of you in the process of trying to setup a similar system, here. They're trying to get this all working with Maven, I'm not sure if you are also, but either way you can then see the link they've been using to help them with their script:

https://github.com/SonarSource/sonarqube/blob/master/travis.sh

This shows they need to write a script that will retrieve the pull number dynamically for them. I think you may need to follow a similar approach and write a script that will retrieve the number for you, I believe one of the github conf files keeps track of the current pull request number for its own tracking purposes.

Not really as straight forward an answer as you might have been hoping for, but hopefully this is new information that helps you get there.