Skip to main content

CircleCI Pipeline

Add the following job to your .circleci/config.yml. It triggers on pushes to the configured branches:
For monorepo projects, add the module name parameter -m module_name to the upload script. To upload coverage for multiple modules from a single commit, invoke upload_coverage.sh once per module - each invocation with its own -f, -m, and -d. A single invocation with multiple -m flags will only honor the last value and attribute every file to that one module. See Multiple Coverage Files (Monorepo) below for the recommended setup.

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 -m module_name and -d module_path. CodeAnt AI keeps the reports separate so each module is tracked, displayed, and gated independently. Without a module name, every upload writes to the same key and later jobs overwrite earlier ones. Define the upload job once with job parameters and invoke it from the workflow once per module. Each invocation becomes its own parallel job; adding a new module is one new entry in workflows.build.jobs.
CircleCI runs each invocation as its own job (upload-backend, upload-frontend, upload-api) in parallel. Adding a new module is one extra block under workflows.build.jobs.
CircleCI’s matrix directive can also fan a job out across parameter combinations, but it requires every required parameter to be supplied via the matrix. It’s a fit only when module_path and coverage_file follow a strict convention you can express as lists - otherwise stick with the explicit per-module entries above.

Alternative: sequential uploads in a single job

If you don’t need parallel uploads, keep the original single-job layout from the top of this page and call the upload script once per module - each invocation with its own -f, -m, and -d:

Environment Variables Configuration

Create a CodeAnt token in CodeAnt AI under API Tokens in the user menu (your email at the bottom-left) - see API Tokens, then add it to CircleCI:
  1. Go to Project Settings -> Environment Variables
  2. Click Add Environment Variable
  3. Add variable name: CODEANT_TOKEN
  4. Paste your CodeAnt token (cdt_…) as the value
  5. Click Add Environment Variable
Alternatively, use a context for organization-wide settings:
  1. Go to Organization Settings -> Contexts
  2. Create a context named codeant-context
  3. Add the CODEANT_TOKEN variable with your CodeAnt token

Coverage config file

You have to create a .coveragerc file in the project’s root folder to include all the source files in the test coverage calculation. Example:
When you assign source to ”.” , It checks for every python file in the root folder and its sub directories. You can omit some directories by placing them in the omit section of the file.

How it works

With the above configuration:
  1. coverage run -m pytest tests/ will count every .py under the workspace as “valid” lines except for those in the omitted directories.
  2. Lines actually executed by your tests are marked “covered.”
  3. coverage xml -o coverage.xml produces a Cobertura-style report reflecting true coverage over the entire codebase.
  4. Using this coverage xml, we calculate the coverage percentage and the status check will be done on every new push to the branch.

Troubleshooting

Coverage file not found

If the coverage file is not generated:
  • Verify tests are running successfully
  • Check that coverage is installed: pip install coverage
  • Ensure the correct test command is used
  • Check the working directory

Upload fails with authentication error

If you see “Access token invalid”:
  • Verify the CODEANT_TOKEN environment variable holds a valid CodeAnt token (cdt_…) that hasn’t been revoked
  • Ensure the token belongs to the same organization as the repository
  • Check that you’re using the correct context or project environment variables

Coverage percentage is 0%

If coverage shows 0%:
  • Check your .coveragerc configuration
  • Verify the source paths are correct
  • Ensure tests are actually exercising the code
  • Check omit patterns aren’t excluding too much

Branch name extraction issues

CircleCI automatically provides:
  • CIRCLE_BRANCH: The branch name
  • CIRCLE_SHA1: The commit SHA
  • CIRCLE_PROJECT_USERNAME: The organization/username
  • CIRCLE_PROJECT_REPONAME: The repository name## Token permission
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.