Enabling Clover for Bamboo

このページの内容

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

This page describes how to enable and configure Atlassian Clover or OpenClover app for a job in Bamboo.

Bamboo を Clover と統合すると、次のことが可能になります。

  • 各ビルド結果のコード カバレッジの詳細 (つまり、テストでカバーされたコードの割合) を表示する
  • ジョブの一定期間におけるコード カバレッジの傾向を表示する
  • ジョブのコード カバレッジの要約を表示する




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")

Enabling automatic code coverage integration

Automatic integration works with Ant, Maven and Grails tasks.

  1. Go to your job. See Configuring jobs.
  2. Click the Other tab.
  3. In the 'Would you like to view code coverage for this plan?' setting, check Collect code coverage data for this job.
  4. Select Automatically integrate a code coverage tool into this job.
  5. In the Code coverage tool option, select Atlassian Clover (you will need to provide a Clover license in Administration > Manage Apps > Clover for Bamboo) or OpenClover (no license is required).
  6. 保存 をクリックします。

By default, HTML and XML reports are generated. Additionally, you can:

  • Select Generate a historical report to compare the current coverage results with previous code coverage reports.
  • Select Generate a JSON report to get the results in a format ready for embedding into applications or external report views.


自動統合時の動作...

When automatic code coverage integration is enabled, Bamboo:

  • Creates an artifact named Clover Report (System), which is visible on the 'Artifacts' tab for the job.

そして、各ビルドの実行時に次のことが行われます。

  • Extracts the Clover license (if set in the administration panel) into a temporary file and passes it to:
    • Ant タスク (-Dclover.license.path=/<bamboo-home>/xml-data/build-dir/<your-job>/.clover/clover.license として)
    • Maven タスク (-Dmaven.clover.licenseLocation=/<bamboo-home>/xml-data/build-dir/<your-job>/.clover/clover.license として)
  • Enhances tasks by adding
      • Ant - targets like "with.clover", "clover.report"
      • Maven - goals like "clover2:setup", "clover2:aggregate", "clover2:clover", "clover2:save-history"; it also adds "verify" phase if original command does not call "compile" or later phase
      • Grails - options like "-clover.on"
  • Generates XML and HTML reports
  • Generates statistics and charts for a plan summary

In order to protect you against publishing instrumented code, automatic Clover integration will not run if the Maven task runs the "install" or "deploy" phases. In such case, you will find no Clover report and a build log will contain an appropriate warning message. In order to get coverage reports for such job, either edit the Maven task to run the build till the "verify" phase (or earlier) or configure Clover manually. An alternative is to add -Dmaven.clover.repositoryPollutionProtection=false property to your Maven task.

 Enabling manual code coverage integration

Manual code coverage integration works with any kind of task in which Clover can be called (Ant, Maven, Command, Grails). Use it when you already have Atlassian Clover or OpenClover integration configured to generate a report in your build scripts:

  1. Go to your job. See Configuring jobs.
  2. Click the Other tab.
  3. In the 'Would you like to view code coverage for this plan?' settings, check Collect code coverage data for this job.
  4. Select I already integrated a code coverage tool in this job.
  5. In Coverage report, specify where Bamboo shall look for the XML report file generated. Specify the file path relative to your plan's root directory, e.g.:

     target/site/clover/clover.xml 
  6. 保存をクリックします。

  7. In the Artifacts tab, click Create artifact 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 **/*.*

  8. Configure Atlassian Clover or OpenClover in your build script so that it generates both XML and HTML reports. See quick start guides how to do this:

  9. For Atlassian Clover configure the license in your build script or pass it as a proper task parameter in the job configuration:

    1. Save the license key in a file (for example in /opt/bamboo/clover.license).
    2. 次の方法で、ライセンス キーの場所をビルド タスクに渡します。
      • ビルド スクリプトで場所を定義する
      • 計画設定の Ant/Maven タスクの Java プロパティとして渡す

Example for Ant ...
build.xml
<project>
  <property name="clover.license.path" location="/opt/bamboo/clover.license"/>
</project>

または

clean with.clover test clover.report -Dclover.license.path=/opt/bamboo/clover.license
Example for Maven ...
pom.xml
<plugin>
    <groupId>com.atlassian.maven.plugins</groupId>
    <artifactId>maven-clover2-plugin</artifactId>
    <configuration>
        <licenseLocation>/opt/bamboo/clover.license</licenseLocation>
    </configuration>
</plugin>

または

mvn clean clover2:setup verify clover2:aggregate clover2:clover -Dmaven.clover.licenseLocation=/opt/bamboo/clover.license


After every build, Bamboo will parse the Clover XML file and generate statistics and charts for a plan summary. The Plan summary and job summary pages will contain a Clover tab. 

Browsing code coverage results

For more information on Clover HTML report and Clover statistics for a job, see Viewing the Clover code-coverage for a plan

For more information on Clover code coverage summary for a plan, see Viewing the Clover code-coverage for a build.

For more information on Clover code coverage statistics across multiple plans, see Generating reports across multiple plans.

Limit the machines that Atlassian Clover runs on

If you have more remote agents than the number of machines for which Atlassian Clover is licensed, you can restrict the machines on which Clover runs by using capabilities:

  1. For each of the EC2 images on which you would like to run builds with Atlassian Clover, add a capability such as clover=true to the configuration for the image.
    To do this, go to Administration > Elastic Bamboo > Configuration. Select the elastic image and click Add Capability.
  2. Add a matching requirement, such as clover=true to the configuration for each job.
    To do this, go to Actions > Configure Plan > Jobs. Select the job where Clover runs and click Requirements and then Add Extra Requirement.

トラブルシューティング

NoClassDefFoundError during execution ...

Using automatic Clover integration or adding a dependency to the maven-clover2-plugin manually is usually sufficient.

ただし、ビルドが別の JVM プロセスを生成する場合 (例: フォークされた JVM で実行されるユニット テスト、その場でインスタンス化されたコンテナーでのテスト、別のサーバーにデプロイされたコードの呼び出しテスト)、その生成されたプロセスの依存関係を Clover JAR に手動で追加する必要があります。

See NoClassDefFoundError com_atlassian_clover/CoverageRecorder KB article.

Automatic integration and building in a subdirectory...

In case you perform a build in a subdirectory (for instance, in the Maven Task configuration you have the "Working sub directory" field set) and you have automatic Clover integration, you may need to correct the Location in the "Clover Report (System)" artifact. Otherwise, an HTML report may be empty as automatic Clover integration uses the default path (for instance, the "target/site/clover" in case of integration with Maven). 

This issue has been fixed in Bamboo 5.7.

Automatic integration and multi-module Maven projects...

If you have a multi-module Maven project with dependencies between modules and use Automatic Clover integration, it can happen that an instrumented JAR of the dependent artifact will be taken for test execution in a build phase where Clover was not enabled yet. See BAM-13208 for more details. In such case, we recommend the following:

  • 自動 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'.



Last modified on Mar 15, 2024

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.