Documentation Index
Fetch the complete documentation index at: https://docs.codeant.ai/llms.txt
Use this file to discover all available pages before exploring further.
Jenkins Pipeline
Add the following stage to yourJenkinsfile. It triggers on pushes to the configured branches:
-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 stages overwrite earlier ones.
Recommended: declarative matrix
Jenkins declarative pipelines support a matrix directive that fans a stage out across axis values, with each cell running in parallel. Define the upload once and let the matrix generate one cell per module.
MODULE = backend, MODULE = frontend, etc. — and runs them in parallel. Adding a new module is one new value in the axis.
If your MODULE_PATH or COVERAGE_FILE can’t be derived uniformly from the module name, use explicit parallel stages instead (see below).
Branch resolution:${GIT_BRANCH#origin/}works for classic freestyle/pipeline jobs that check out a single ref. On multibranch pipelines, useenv.BRANCH_NAMEinstead; on PR builds (via the GitHub/Bitbucket Branch Source plugins),env.CHANGE_BRANCHholds the source branch whileenv.BRANCH_NAMEis set toPR-<n>. Swap the-bargument to whichever variable your job type populates.
Alternative: explicit parallel stages
If you prefer the explicit form (e.g. each module has a fully different test command, or paths and files don’t follow a convention), declare each upload as its own stage and run them with parallel:
Credentials Configuration
Add your access token to Jenkins credentials:- Go to Manage Jenkins -> Credentials -> System -> Global credentials
- Click Add Credentials
- Select Secret text as the kind
- Enter
ACCESS_TOKENas the ID - Paste your Github access token as the secret
- Add a description like “GitHub Access Token”
- Click Create
Token Permissions
The access token requires the following permissions:- Metadata: Read-only access
- Commit statuses: Read and write access
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:
How it works
With the above configuration:coverage run -m pytest tests/will count every .py under the workspace as “valid” lines except for those in the omitted directories.- Lines actually executed by your tests are marked “covered.”
coverage xml -o coverage.xmlproduces a Cobertura-style report reflecting true coverage over the entire codebase.- 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
ACCESS_TOKENcredential is correctly configured - Ensure the token has the required permissions
- Check that the credential ID matches exactly
Coverage percentage is 0%
If coverage shows 0%:- Check your
.coveragercconfiguration - 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
If the branch name is incorrect:- Debug with
echo "Branch: ${env.GIT_BRANCH}" - Handle different branch name formats
- Consider using
env.BRANCH_NAMEfor multibranch pipelines