jenkins + sonar + github integration

后端 未结 2 757
盖世英雄少女心
盖世英雄少女心 2020-12-04 16:11

Problem: I am setting up jenkins + sonar + github integration for automatic pullrequest static code check through sonar.

My

2条回答
  •  Happy的楠姐
    2020-12-04 16:26

    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 jdk
    • Install sonarQube Runner
    • Configure Sonar
    • Git WebHook Setup
    • PullRequest Builder Setup

      1. Create Free Style Jenkins job
    • add github url to GitHub Project section

    • Setup Source Code Management Section

    • Setup Build Trigger

    • Setup Sonar for post build actions

    • 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.

提交回复
热议问题