Enabling Clover for Bamboo
This page describes how to enable and configure Atlassian's Clover app for a job in Bamboo.
Bamboo を Clover と統合すると、次のことが可能になります。
- 各ビルド結果のコード カバレッジの詳細 (つまり、テストでカバーされたコードの割合) を表示する
- ジョブの一定期間におけるコード カバレッジの傾向を表示する
- ジョブのコード カバレッジの要約を表示する
このページの内容
Enable the Clover app
- 「ジョブの設定」の説明に従って、目的のジョブに移動します。
- [Actions (アクション)] > [Configure Job (ジョブを設定)] の順に選択します。
- [Miscellaneous (その他)] タブをクリックします。
Select Use Clover to collect Code Coverage for this build and set the following:
- Automatically integrate Clover into this build
You will need to provide a Clover license, unless this has been configured globally in the Administration panel (Administration > Plugins > Clover Plugin). - Generate a Clover Historical Report
Displays the current coverage results compared with previous Clover code coverage reports. - Generate a JSON report
Provides the Clover results in a format ready for embedding into applications or external report views. - Use plan-defined Clover license key
Override the global Clover license for this particular plan. - Clover is already integrated into this build
Use this option when you already have Clover-for-Ant, Clover-for-Maven or another Clover integration configured to generate a report. Clover XML Location
Specify the location where Bamboo will look for the XML report file from Clover. Please specify the file path relative to your plan's root directory (e.g/home/bamboouser/bamboo-home/xml-data/build-dir/MY_PLAN/
), i.e. do not specify an absolute path.target/site/clover/clover.xml
- Automatically integrate Clover into this build
Screenshot: Settings to enable Clover for a job:
As Clover integration (automatic and manual) produces instrumented classes, we recommend that you ensure that your job does not install them to production (for instance: 'mvn deploy' to public repository, 'scp' to an application server running on production, etc ...). Having instrumented code in such locations is usually not desired.
Common practices to ensure proper separation of instrumented and non-instrumented classes are:
- create a dedicated plan or job with Clover integration enabled
- enable automatic Clover integration for jobs running tests only (e.g. "mvn verify")
- use different location of local artifact cache if you need to install artifacts (e.g. ~/.m2/repository-clover and "mvn install")
- use different URL for uploading artifacts if necessary (e.g. a separate repository for "mvn deploy")
Clover の自動統合
自動統合は、Ant、Maven 2.x、Maven 3.x、および Grails タスクと連携します。
- Clover コード カバレッジ設定で、[Use Clover to collect Code Coverage for this build (Clover を使用してこのビルドのコード カバレッジを収集する)] を選択します。
- [Automatically integrate Clover into this build (このビルドに Clover を自動的に統合する)] を選択します。
- Enter the global license key for Clover (go to Administration > Plugins > Clover Plugin), or enable Use plan-defined Clover license key and paste the key into the text field that appears.
さらに、次のことが可能です。
- [Generate a Clover Historical Report (Clover 履歴レポートを生成する)] を選択して、現在のカバレッジ結果を以前の Clover コード カバレッジ レポートと比較します。
- [Generate a JSON report (JSON レポートを生成する)] を選択して、アプリまたは外部レポート ビューに組み込める形式で Clover 結果を取得します。
Clover の手動統合
Clover の手動統合は、Clover の呼び出しが可能なあらゆる種類のタスク (Ant、Maven 2.x、Maven 3.x、Command、Grails) と連携します。
- Clover コード カバレッジ設定で、[Use Clover to collect Code Coverage for this build (Clover を使用してこのビルドのコード カバレッジを収集する)] を選択します。
- [Clover is already integrated into this build (Clover はこのビルドに統合済み)] を選択します。
- 参照場所を指定します。 Clover によって生成された XML レポート ファイルはここで Bamboo によって参照されます。
On the 'Artifacts' tab, click Create Definition and complete the form as follows:
Name
This should begin with with "Clover Report".
Location
This should point to the HTML report directory (e.g. target/site/clover)
Copy Pattern
Use **/*.*ビルド スクリプトで Clover を設定して、XML と HTML の両方のレポートが生成されるようにします。
ビルド スクリプトで Clover ライセンスを設定するか、ジョブ設定の適切なタスク パラメーターとして Clover ライセンスを渡します。
- Clover ライセンス キーをファイル (/opt/bamboo/clover.license など) に保存します。
- 次の方法で、ライセンス キーの場所をビルド タスクに渡します。
- ビルド スクリプトで場所を定義する
- 計画設定の Ant/Maven タスクの Java プロパティとして渡す
ビルドのたびに、Bamboo は Clover XML ファイルを解析して、計画要約の統計とチャートを生成します。計画要約ページとジョブ要約ページに [Clover] タブが表示されます。
Clover の結果を参照する
Clover HTML レポートとジョブに関する Clover 統計: 「計画の Clover コード カバレッジの表示」をご確認ください。
計画の Clover コード カバレッジの要約:「ビルドの Clover コード カバレッジの表示」をご確認ください。
複数の計画にわたる Clover コード カバレッジの統計:「複数の計画にわたるレポートの生成」をご確認ください。
Clover が動作するマシンを制限する
- Clover でビルドを実行する EC2 イメージごとに、イメージの設定に「clover=true」などの機能を追加します。
これを行うには、[管理] > [Elastic Bamboo] > [設定] に移動します。エラスティック イメージを選択して、[Add Capability (機能を追加)] をクリックします。 - 「clover=true」などの一致要件を各ジョブの設定に追加します。
これを行うには、[アクション] > [プランを構成] > [ジョブ] の順に移動します。Clover を実行するジョブを選択して、[要件] をクリックし、次に [Add Extra Requirement (要件を追加)] をクリックします。
トラブルシューティング
自動または手動の Clover 統合と生成されたプロセス
通常は、自動 Clover 統合を使用するか、maven-clover2-plugin に依存関係を手動で追加するだけで十分です。
ただし、ビルドが別の JVM プロセスを生成する場合 (例: フォークされた JVM で実行されるユニット テスト、その場でインスタンス化されたコンテナーでのテスト、別のサーバーにデプロイされたコードの呼び出しテスト)、その生成されたプロセスの依存関係を Clover JAR に手動で追加する必要があります。
ナレッジ ベース記事の「NoClassDefFoundError com_atlassian_clover/CoverageRecorder」をご確認ください。
自動 Clover 統合とサブディレクトリでの構築
サブディレクトリでビルドを実行して (たとえば Maven タスクの構成で "作業サブディレクトリ" フィールドを設定して)、自動 Clover 統合がある場合、"Clover レポート (システム)" アーティファクトのロケーションを修正しなければならない場合があります。修正しないと、自動 Clover 統合で既定のパス (たとえば Maven との統合の場合は "target/site/clover") が使用されるため、HTML レポートが空になる可能性があります。
This issue has been fixed in Bamboo 5.7.
自動 Clover 統合とマルチモジュール Maven プロジェクト
モジュール間に依存関係があるマルチモジュール Maven プロジェクトを持ち、自動 Clover 統合を使用している場合、Clover がまだ有効になっていなかったビルド フェーズで、依存アーティファクトのインストゥルメント化された JAR がテスト実行に利用されることがあります。詳細は BAM-13208 をご確認ください。このような場合は次をお勧めします。
- 自動 Clover 統合が有効になっている別のジョブを作成します。
- このジョブに何もしない Maven タスクを作成します ("クリーン" ゴールと呼ぶなど)。
- Bamboo は Clover に関連するゴールを自動的に追加します (clover2:setup verify clover2:aggregate clover2:clover)。
This issue has been fixed in Bamboo 5.9.
Clover Results Collector is unable to find the XML report file
In the build log you may see a warning like:
Failed to execute plugin 'Clover Results Collector' with error: No file matches the specified pattern ...
The are several possible reasons, see this article for more details: Failed to execute plugin 'Clover Results Collector'.