페이지 트리

Building GitHub pull requests with TeamCity

Pull Request Analysis

Decorating Pull Requests

For GitHub Enterprise, the minimum version is 2.14

Creating a GitHub App

You can add Pull Request decoration under the GitHub Checks tab or Conversation tab. To do this, an instance administrator must first create a GitHub App:

  1. Follow Steps 1–4 here to start creating your GitHub App.
  2. Under GitHub App name, give your app a name (such as SonarQubePRChecks).
  3. GitHub requires a Homepage URL and a Webhook URL. These values aren't important for Pull Request decoration, so you can use any URL (such as https://www.sonarqube.org/).
  4. Grant access for the following Permissions

    PermissionAccess
    ChecksRead & write
    GitHub Enterprise: Repository metadata 
    GitHub.com: Metadata
    Read-only
    Pull RequestsRead & write
    Commit statusesRead-only
  5. Under "Where can this GitHub App be installed?," select Any account
  6. Click Create GitHub App. This will take you to your new GitHub App's page. 
  7. Scroll down to the bottom of your app page and click Generate Private Key. This downloads a .pem file that you'll use in the Setting your global settings section. 

Installing your app

Install your GitHub App from the app's settings page. See the GitHub instructions for more information.

Setting your global settings

To set your global settings in SonarQube, navigate to Administration > Configuration > General Settings > ALM Integrations and select the GitHub tab.

From here, set your Configuration NameGitHub Instance URLGitHub App ID, and your GitHub App's Private Key (that was generated above in the Creating a GitHub Appsection).

Note: Make sure the Configuration name is succinct and easily recognizable as it will be used at the project level to identify the correct ALM configuration.

Setting your project settings

Go to Project Settings > General Settings > Pull Request Decoration, select your Configuration Name, and set your Repository identifier.

By default, Enable analysis summary under the GitHub Conversation tab is on and your Pull Request analysis will be shown under the Conversation and Checks tabs in GitHub. Turning this setting off will make it so Pull Request analysis is only shown under the Checks tab.

Teamcity SonarQube Plugin

https://github.com/JetBrains/TeamCity.SonarQubePlugin/issues/69

Adding Pull Request Analysis (in GitHub Pull Request decoration for sample), configuring parameters could be a little tricky.

You have parameters:

  • On build: sonar.pullrequest.key / sonar.pullrequest.branch / sonar.pullrequest.base ; to set on build
  • On project config: sonar.pullrequest.provider / sonar.pullrequest.github.repository ; to configure in UI

All these parameters could be retrieved from TeamCity build parameters (at least for GitHub). If it can be provisionned by a TeamCity Build Feature, it would be great !!

This feature request is like the Using SonarCloud with Travis CI, which is very usefull.

Technically, it seems to work with the SONARQUBE_SCANNER_PARAMS system environment variable ; available since SonarQube Scanner API v2.7 (SCANNERAPI-159) & SonarQube Scanner for Maven v3.1 (MSONAR-147).

Content of this sysenv depending the build (Here GitHub+Travis classic & PR builds):

# Classic Build
SONARQUBE_SCANNER_PARAMS = { "sonar.organization" : "axel3rd-github", "sonar.host.url" : "https://sonarcloud.io" }

# PullRequest build
SONARQUBE_SCANNER_PARAMS = { "sonar.pullrequest.key" : "1", "sonar.pullrequest.branch" : "branch", "sonar.pullrequest.base" : "master", "sonar.pullrequest.provider" : "GitHub", "sonar.pullrequest.github.repository" : "axel3rd/sysenv-travis-watcher", "sonar.organization" : "axel3rd-github", "sonar.host.url" : "https://sonarcloud.io" }

And you are right, if these data (PR feature) can be used, the mapping can be done more easiest than some build parameters.

Currently I can see for GitHub PR (EDITED 24/10: Update with last TW-61490 remark ;  Pull Requests TeamCity plugin version 66559 at min).

SonarQube parameterTeamCity parameterRemark
sonar.pullrequest.keyteamcity.pullRequest.number--
sonar.pullrequest.branchteamcity.pullRequest.titleUsed in SonarQube UI only
sonar.pullrequest.baseteamcity.pullRequest.target.branch
sonar.pullrequest.providerTo extract from vcsroot.urlIn discussion in TW-61490
sonar.pullrequest.github.repositoryvcsroot.urlWith an extract from complete SCM URL (before last \, or .*github.*/(.*)/(.*)--> \1/\2)
sonar.organization--Seems not used into SonarQube
sonar.host.urlDefined in plugin configuration, or require #70

  • 레이블 없음