Skip to main content

Overview

Upload test coverage reports to CodeAnt AI for comprehensive analysis, visualization, and tracking of your code coverage metrics. Reference Repository: codeant-coverage

Features

  • 📊 Upload coverage reports in multiple formats (XML, JSON, LCOV, etc.)
  • 🔍 Automatic coverage analysis and insights
  • 📈 Track coverage trends over time
  • 🎯 Integration with pull requests
  • 🚀 Easy setup with minimal configuration
  • 🏢 Support for self-hosted/enterprise instances

Prerequisites

Before using the pipe, configure these repository variables in Repository Settings → Pipelines → Repository variables:
  • ACCESS_TOKEN - Your Bitbucket access token with write access to the repository

Basic Usage

Example 1: Basic Coverage Upload

image: python:3.11

pipelines:
  default:
    - step:
        name: Run tests and generate coverage
        script:
          - pip install pytest pytest-cov
          - pytest --cov=. --cov-report=xml:coverage.xml

    - step:
        name: Upload coverage to CodeAnt AI
        script:
          - pipe: docker://public.ecr.aws/d2p9q4a9/codeant-coverage:latest
            variables:
              ACCESS_TOKEN: $ACCESS_TOKEN
              COVERAGE_FILE: coverage.xml

Example 2: Pull Request Coverage Analysis

image: python:3.11

pipelines:
  pull-requests:
    '**':
      - step:
          name: Test and Coverage
          caches:
            - pip
          script:
            - pip install pytest pytest-cov
            - pytest --cov=. --cov-report=xml:coverage.xml

      - step:
          name: Upload to CodeAnt AI
          script:
            - pipe: docker://public.ecr.aws/d2p9q4a9/codeant-coverage:latest
              variables:
                ACCESS_TOKEN: $ACCESS_TOKEN
                COVERAGE_FILE: coverage.xml

Example 3: Advanced Configuration with Debug Mode

- step:
    name: Upload coverage to CodeAnt AI
    script:
      - pipe: docker://public.ecr.aws/d2p9q4a9/codeant-coverage:latest
        variables:
          ACCESS_TOKEN: $ACCESS_TOKEN
          COVERAGE_FILE: coverage.xml
          API_BASE_URL: https://api.codeant.ai
          PLATFORM: bitbucket
          FAIL_ON_ERROR: 'true'
          DEBUG: 'false'

Configuration Variables

VariableRequiredDefaultDescription
ACCESS_TOKENYes-Bitbucket access token for authentication with CodeAnt AI
COVERAGE_FILEYescoverage.xmlPath to the coverage file (e.g., coverage.xml, coverage.json)
API_BASE_URLNohttps://api.codeant.aiCodeAnt AI API base URL (for self-hosted instances)
PLATFORMNobitbucketGit platform (github, gitlab, bitbucket)
FAIL_ON_ERRORNotrueFail the build if coverage upload fails
DEBUGNofalseEnable debug logging

Supported Coverage Formats

  • Cobertura XML (.xml)
  • JaCoCo XML
  • LCOV (.lcov)
  • JSON coverage reports
  • Clover XML
  • And more…

Language-Specific Examples

Python with pytest

image: python:3.11

pipelines:
  pull-requests:
    '**':
      - step:
          name: Test and Coverage
          caches:
            - pip
          script:
            - pip install pytest pytest-cov
            - pytest --cov=. --cov-report=xml:coverage.xml

      - step:
          name: Upload to CodeAnt AI
          script:
            - pipe: docker://public.ecr.aws/d2p9q4a9/codeant-coverage:latest
              variables:
                ACCESS_TOKEN: $ACCESS_TOKEN

JavaScript with Jest

image: node:18

pipelines:
  pull-requests:
    '**':
      - step:
          name: Test and Coverage
          caches:
            - node
          script:
            - npm install
            - npm test -- --coverage --coverageReporters=cobertura

      - step:
          name: Upload to CodeAnt AI
          script:
            - pipe: docker://public.ecr.aws/d2p9q4a9/codeant-coverage:latest
              variables:
                ACCESS_TOKEN: $ACCESS_TOKEN
                COVERAGE_FILE: coverage/cobertura-coverage.xml

Java with Maven

image: maven:3.8-openjdk-11

pipelines:
  pull-requests:
    '**':
      - step:
          name: Test and Coverage
          caches:
            - maven
          script:
            - mvn clean test jacoco:report

      - step:
          name: Upload to CodeAnt AI
          script:
            - pipe: docker://public.ecr.aws/d2p9q4a9/codeant-coverage:latest
              variables:
                ACCESS_TOKEN: $ACCESS_TOKEN
                COVERAGE_FILE: target/site/jacoco/jacoco.xml

Go with go-cover

image: golang:1.21

pipelines:
  pull-requests:
    '**':
      - step:
          name: Test and Coverage
          script:
            - go test -coverprofile=coverage.out ./...
            - go tool cover -func=coverage.out

      - step:
          name: Upload to CodeAnt AI
          script:
            - pipe: docker://public.ecr.aws/d2p9q4a9/codeant-coverage:latest
              variables:
                ACCESS_TOKEN: $ACCESS_TOKEN
                COVERAGE_FILE: coverage.out

Coverage Configuration

Python Coverage Configuration

Create a .coveragerc file in your project’s root folder to include all source files in the test coverage calculation:
[run]
# include every Python file under the repo root
source = .

# exclude tests, virtualenvs, build artifacts, etc.
omit =
    */tests/*
    */.venv/*
    */build/*
    */dist/*
When you assign source to ., it checks for every Python file in the root folder and its subdirectories. You can omit directories by placing them in the omit section.

How It Works

  1. The pipe fetches the latest coverage upload script from CodeAnt AI
  2. Automatically decodes and prepares the script for execution
  3. Uploads your coverage report along with commit and repository information
  4. CodeAnt AI processes the report and provides analysis on your pull requests
  5. Lines executed by your tests are marked as “covered”
  6. Coverage percentage is calculated and status checks are performed on every push

Troubleshooting

Enable Debug Mode

Set DEBUG: 'true' to see detailed logs:
- pipe: docker://public.ecr.aws/d2p9q4a9/codeant-coverage:latest
  variables:
    ACCESS_TOKEN: $ACCESS_TOKEN
    DEBUG: 'true'

Coverage File Not Found

Issue: Coverage file not found error Solution: Ensure the coverage file is generated before upload and verify the COVERAGE_FILE path is correct. Use artifacts to pass files between steps if needed.

Upload Fails But Pipeline Continues

Issue: Upload fails but pipeline continues Solution: Set FAIL_ON_ERROR: 'false' to continue the pipeline even if upload fails (default is true).

Authentication Errors

Issue: Authentication errors during upload Solution: Verify your ACCESS_TOKEN is valid, has write access, and is marked as secured in Repository Variables.

Low Coverage Reporting

Issue: Coverage reporting is lower than expected Solution: Check your coverage configuration file (e.g., .coveragerc), ensure all source files are included, and verify omit patterns aren’t excluding too much code.

Support

License

MIT License - see LICENSE file for details
I