Skip to content

Instantly share code, notes, and snippets.

@minazou67
Last active October 23, 2018 12:31
Show Gist options
  • Save minazou67/00fd11b40c6a0d7bb578c976bb18b71d to your computer and use it in GitHub Desktop.
Save minazou67/00fd11b40c6a0d7bb578c976bb18b71d to your computer and use it in GitHub Desktop.
How to integrate Jenkins and SonarQube

How to integrate Jenkins and SonarQube

Jenkins と SonarQube を連携する方法です。

Environment

  • Maven 3.3+
  • Jenkins 2.146
    • SonarQube Scanner for Jenkins 2.8.1
  • SonarQube 7.1

Introduction

Jenkins と SonarQube の連携には、複数の方法が存在します。
それぞれメリット、デメリットが存在するので、それについてのメモです。

Preparation

Jenkins の管理画面で下記の設定が必要です。

  • システムの設定
    • SonarQube servers
  • Global Tool Configuration
    • SonarQube Scanner

「Maven プロジェクトのビルド」形式のジョブを作成します。

Integration method

後処理の追加

Execute SonarQube Scanner を追加します。
デフォルトではプロジェクトルート直下の sonar-project.properties が読み込まれます。
Maven のマルチモジュール構成の場合は、サブモジュール毎の設定が必要となるため設定ファイルの作成が面倒です。

ビルド後の処理の追加

SonarQube analysis with Maven を追加します。
「高度な設定」から BranchJDK を設定します。
Maven のマルチモジュール構成でも想定通りの動作をしますが、現在は非推奨となっています。

Maven ビルド

親モジュールの pom.xml に SonarQube サーバーの URL を指定します。

<properties>
  <sonar.host.url>http://sonarserver:9000</sonar.host.url>
</properties>

「ビルド」の「ゴールとオプション」に sonar:sonar を追加します。
Maven のマルチモジュール構成でも想定通りの動作をしますが、ジョブ画面に SonarQube へのリンクが表示されません。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment