Jenkins と SonarQube を連携する方法です。
- Maven 3.3+
- Jenkins 2.146
- SonarQube Scanner for Jenkins 2.8.1
- SonarQube 7.1
Jenkins と SonarQube の連携には、複数の方法が存在します。
それぞれメリット、デメリットが存在するので、それについてのメモです。
Jenkins の管理画面で下記の設定が必要です。
- システムの設定
- SonarQube servers
- Global Tool Configuration
- SonarQube Scanner
「Maven プロジェクトのビルド」形式のジョブを作成します。
Execute SonarQube Scanner
を追加します。
デフォルトではプロジェクトルート直下の sonar-project.properties
が読み込まれます。
Maven のマルチモジュール構成の場合は、サブモジュール毎の設定が必要となるため設定ファイルの作成が面倒です。
SonarQube analysis with Maven
を追加します。
「高度な設定」から Branch
や JDK
を設定します。
Maven のマルチモジュール構成でも想定通りの動作をしますが、現在は非推奨となっています。
親モジュールの pom.xml
に SonarQube サーバーの URL を指定します。
<properties>
<sonar.host.url>http://sonarserver:9000</sonar.host.url>
</properties>
「ビルド」の「ゴールとオプション」に sonar:sonar
を追加します。
Maven のマルチモジュール構成でも想定通りの動作をしますが、ジョブ画面に SonarQube
へのリンクが表示されません。