Skip to main content

CodeAnt AI Coverage Upload for GitLab

Upload test coverage reports to CodeAnt AI for comprehensive analysis, visualization, and tracking of your code coverage metrics.

Features

  • 📊 Upload coverage reports in XML format (Cobertura XML, JaCoCo XML)
  • 🔍 Automatic coverage analysis and insights
  • 📈 Track coverage trends over time
  • 🎯 Integration with merge requests
  • 🚀 Easy setup with minimal configuration

Usage

Basic Example

Advanced Example

Inputs

ACCESS_TOKEN must be added as a project (or group) CI/CD variable so it can be masked - never paste it into your .gitlab-ci.yml. The remaining variables go under variables: inside the upload job. Set as a CI/CD variable Set under variables: in your .gitlab-ci.yml

Supported Coverage Formats

Important: Only XML format is supported for coverage reports.
  • Cobertura XML (.xml)
  • JaCoCo XML

Setup

1. Create a CodeAnt Token

In CodeAnt AI, open the user menu (click your email at the bottom-left) and select API Tokens, click Create token, and copy the generated token (it starts with cdt_ and is shown only once). See API Tokens for the full walkthrough. This single token authenticates the upload - you don’t need a GitLab access token.

2. Generate Coverage Report

First, ensure your test suite generates a coverage report. Here are examples for common languages: Python (pytest)
JavaScript/TypeScript (Jest)
Java (Maven)
Go

3. Add CI/CD Variables

Add your CodeAnt token to your GitLab project:
  1. Go to your repository Settings
  2. Navigate to CI/CD > Variables
  3. Click “Add variable”
  4. Key: ACCESS_TOKEN (this is the variable name the included template reads)
  5. Value: Your CodeAnt token (cdt_…)
  6. Protected: Yes (recommended)
  7. Masked: Yes (recommended)

4. Configure Pipeline

Add the template to your .gitlab-ci.yml as shown in the usage examples above.

How It Works

  1. The job fetches the latest coverage upload script from CodeAnt AI
  2. Decodes and prepares the script for execution
  3. Uploads your coverage report along with commit and branch information
  4. CodeAnt AI processes the report and provides analysis

Examples

Python Project

Node.js Project

Java Project

Multiple Coverage Files (Monorepo)

When a single commit produces several coverage reports - for example one per service in a monorepo - give each upload its own MODULE and MODULE_PATH. CodeAnt AI keeps the reports separate so each module is tracked, displayed, and gated independently. Without MODULE, every upload writes to the same key and later jobs overwrite earlier ones.
  • MODULE is the logical name shown in the UI (e.g. backend, frontend).
  • MODULE_PATH is the directory used to resolve source files referenced in the coverage XML (e.g. services/backend). If your XML’s filename attributes are relative to the module root, set MODULE_PATH to that root.
Instead of duplicating the upload block per module, define it once and fan it out with parallel:matrix. Each matrix entry becomes its own parallel job; adding a new module is one new entry instead of an entire job stanza. The job name codeant_coverage matches the one shipped by the included template, so this definition replaces it. Provide your own test_* jobs that emit each module’s coverage XML at the path referenced by COVERAGE_FILE.
GitLab spawns one job per matrix entry - codeant_coverage: [backend, services/backend, services/backend/coverage.xml], codeant_coverage: [frontend, …], etc. - and each one runs the upload independently with its own MODULE, MODULE_PATH, and COVERAGE_FILE.

Alternative: one job per module

If you prefer the explicit form (e.g. you want each module gated by a different upstream needs:), define a job per module:

Troubleshooting

Coverage file not found
  • Ensure the COVERAGE_FILE path is correct and the file exists as an artifact from a previous job.
Authentication failed / Invalid access token
  • Verify that your ACCESS_TOKEN holds a valid CodeAnt token (cdt_…) that hasn’t been revoked. You can check and re-issue tokens under API Tokens (in the user menu - your email at the bottom-left) in CodeAnt AI - see API Tokens.
  • Make sure the token belongs to the same organization/workspace as the repository you’re uploading coverage for. A token is scoped to one provider + organization.
  • If you have an ACCESS_TOKEN defined as a project-level CI/CD variable, it overrides any ACCESS_TOKEN set in .gitlab-ci.yml (project-level CI variables take precedence over YAML variables). Update or remove the project-level variable rather than trying to override it from YAML.
Script execution failed
  • Check that the CodeAnt AI API is accessible from your runner environment.

Contributing

Contributions are welcome! Please feel free to submit a Merge Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

This pipeline authenticates with a CodeAnt API token (cdt_…). If the token is scoped, give it the Codeant CI/CD role - it covers scans, quality gates, and test-coverage upload - scoped to the repositories this pipeline runs on (or All repositories). A token missing the required permission is rejected with an HTTP 403 token_scope_forbidden error that names the permission it needs. See API token permissions.