Sign inSign up

loremfoobar/reportgenerator-coverage-bitbucket-pipe

By loremfoobar

•Updated 10 months ago

Bitbucket Pipelines pipe for generating coverage report using ReportGenerator

Image
Developer tools
0

3.5K

loremfoobar/reportgenerator-coverage-bitbucket-pipe repository overview

⁠Bitbucket Pipelines Pipe: ReportGenerator Coverage Report Pipe

Bitbucket

Generate coverage reports using ReportGenerator⁠ and a build status based on coverage requirements.

⁠YAML Definition

Add the following snippet to the script section of your bitbucket-pipelines.yml file:

script:
  - pipe: docker://loremfoobar/reportgenerator-coverage-bitbucket-pipe:1.0.0
    variables:
      # BITBUCKET_USERNAME: "<string>" # Optional
      # BITBUCKET_APP_PASSWORD: "<string>" # Optional
      # LINE_COVERAGE_MINIMUM: "<int>" # Optional, default: 0
      # BRANCH_COVERAGE_MINIMUM: "<int>" # Optional, default: 0
      # PIPELINE_REPORT_TITLE: "<string>" # Optional, default: BUILD_STATUS_NAME if present, else "Code Coverage"
      # BUILD_STATUS_NAME: "<string>" # Optional, default: PIPELINE_REPORT_TITLE if present, else "Code Coverage"
      # CREATE_BUILD_STATUS: "<boolean>" # Optional, default: true
      # FAIL_WHEN_MINIMUM_NOT_MET: "<boolean>" # Optional, default: false
      # PUBLISHED_REPORT_URL: "<string>" # Optional
      # REPORTS: "<string>" # Optional, default: "**/coverage*.xml"
      # REPORT_TYPES: "<string>" # Optional, default: "JsonSummary;Html"
      # EXTRA_ARGS: ['arg1', 'arg2'] # Optional
      # DEBUG: "<boolean>" # Optional

⁠Variables

VariableUsage
BITBUCKET_USERNAMEBitbucket username, required to create build status. Note, that this should be an account name, not the email.
BITBUCKET_APP_PASSWORDBitbucket app password, required to create build status.
PIPELINE_REPORT_TITLETitle of Pipeline report created by pipe. Default: BUILD_STATUS_NAME if present, else "Code Coverage".
BUILD_STATUS_NAMEName of build status created by pipe. Default: PIPELINE_REPORT_TITLE if present, else "Code Coverage".
CREATE_BUILD_STATUSWhether to create build status reflecting the provided coverage requirements. Default: true.
FAIL_WHEN_MINIMUM_NOT_METWhether to fail current build step when minimum coverage requirements are not met. Default: false
REPORTSPath(s) to coverage reports. Supports globbing. Passed as value of -reports argument to ReportGenerator. Default: **/coverage*.xml.
REPORT_TYPESThe types of reports to generate. Passed as value of -reporttypes argument to ReportGenerator. Default: JsonSummary;Html. Note: JsonSummary is required to enforce minimum requirements.
LINE_COVERAGE_MINIMUMMinimum requirement for line coverage percentage. Default: 0.
BRANCH_COVERAGE_MINIMUMMinimum requirement for branch coverage percentage. Default: 0.
PUBLISHED_REPORT_URLIf you intend to upload coverage report generated by this pipe, this should contain the URL to the published report.
EXTRA_ARGSExtra arguments array that are passed as is to ReportGenerator.
DEBUGTurn on extra debug information. Default: false.

(*) = required variable.

⁠Prerequisites

⁠Code Coverage Files

Code coverage files need to be present when the pipe runs. Different coverage tools exist for different languages/technologies. Whichever tool you use to create the coverage data, it needs to be in one of the formats supported by ReportGenerator, see ReportGenerator Supported File Formats⁠ .

⁠App Password Required for Build Status

Build status will be created only if username and app password are provided. To have this pipe create build status, you need to generate an app password⁠ . Only the Repositories Read permission is required.

⁠Uploading The Report

Report files are generated in folder ./coverage-report. You can use another pipe to upload the report files to your preferred storage provider. If you provide the expected report URL in PUBLISHED_REPORT_URL variable, it will be used as the link for the build status and the Pipeline report for easy access. Depending on your storage provider, you may need to link directly to the index.html file in order to be able browse to it.

⁠Examples

Basic example using secure variables for username and app password:

script:
  - pipe: docker://loremfoobar/reportgenerator-coverage-bitbucket-pipe:1.0.0
    variables:
      BITBUCKET_USERNAME: $USERNAME
      BITBUCKET_APP_PASSWORD: $APP_PASSWORD
      LINE_COVERAGE_MINIMUM: "80"
      BRANCH_COVERAGE_MINIMUM: "80"

Example with published report URL:

script:
  - pipe: docker://loremfoobar/reportgenerator-coverage-bitbucket-pipe:1.0.0
    variables:
      BITBUCKET_USERNAME: $USERNAME
      BITBUCKET_APP_PASSWORD: $APP_PASSWORD
      LINE_COVERAGE_MINIMUM: "80"
      BRANCH_COVERAGE_MINIMUM: "80"
      PUBLISHED_REPORT_URL: "https://my-server.com/coverage/$BITBUCKET_REPO_SLUG/$BITBUCKET_COMMIT/index.html"

Example with extra arguments:

script:
  - pipe: docker://loremfoobar/reportgenerator-coverage-bitbucket-pipe:1.0.0
    variables:
      BITBUCKET_USERNAME: $USERNAME
      BITBUCKET_APP_PASSWORD: $APP_PASSWORD
      LINE_COVERAGE_MINIMUM: "80"
      BRANCH_COVERAGE_MINIMUM: "80"
      REPORTS: "coverage/cobertura.xml"
      REPORT_TYPES: "JsonSummary;HtmlSummary"
      EXTRA_ARGS: [ '-plugins:my-history-storage-plugin.dll', '"-classfilters:+IncludeThisClass;-ExcludeThisClass"' ]
      PUBLISHED_REPORT_URL: "https://my-server.com/coverage/$BITBUCKET_REPO_SLUG/$BITBUCKET_COMMIT/summary.html"

Example with build status creation temporarily disabled:

script:
  - pipe: docker://loremfoobar/reportgenerator-coverage-bitbucket-pipe:1.0.0
    variables:
      BITBUCKET_USERNAME: $USERNAME
      BITBUCKET_APP_PASSWORD: $APP_PASSWORD
      LINE_COVERAGE_MINIMUM: "80"
      BRANCH_COVERAGE_MINIMUM: "80"
      CREATE_BUILD_STATUS: "false"

⁠Support

If you're reporting an issue, please include:

  • the version of the pipe
  • relevant logs and error messages
  • steps to reproduce

⁠License

MIT License⁠

Tag summary

Content type

Image

Digest

sha256:416712f8b…

Size

41 MB

Last updated

10 months ago

docker pull loremfoobar/reportgenerator-coverage-bitbucket-pipe:2.0.0