Skip to main content

Installation

Before using CodeAnt Coverage Upload in your Azure Pipelines, you need to install the CodeAnt extension from the Azure DevOps Marketplace:
  1. Go to the Azure DevOps Marketplace and search for “CodeAnt AI” or directly download from here
  2. Click Get it free
  3. Select your Azure DevOps organization
  4. Click Install
Once installed, the codeant-coverage-upload task will be available in all pipelines across your organization.

Azure DevOps Pipelines Workflow

This pipeline triggers on pushes to the specified branch and performs the following steps:
  1. Runs tests and generates a coverage report
  2. Uploads the coverage XML to CodeAnt AI
trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

steps:
  - checkout: self

  # Run tests and generate coverage
  - script: |
      python -m venv .venv
      source .venv/bin/activate
      pip install --upgrade pip
      pip install coverage pytest

      coverage run -m pytest tests/
      coverage xml -o coverage.xml
    displayName: 'Run tests & generate coverage'

  # Upload coverage to CodeAnt
  - task: codeant-coverage-upload@1
    inputs:
      accessToken: $(ACCESS_TOKEN)
      baseUrl: 'https://api.codeant.ai'
      coveragePath: 'coverage.xml'
    displayName: 'Upload Coverage to CodeAnt'

With Optional Parameters

You can customize the coverage upload with additional parameters:
steps:
  - checkout: self

  # Run tests and generate coverage
  - script: |
      npm install
      npm test -- --coverage
    displayName: 'Run tests'

  # Upload coverage to CodeAnt
  - task: codeant-coverage-upload@1
    inputs:
      accessToken: $(ACCESS_TOKEN)
      baseUrl: 'https://api.codeant.ai'
      coveragePath: 'coverage/coverage.xml'
      platform: 'azuredevops'
      vcsBaseUrl: 'https://dev.azure.com'
    displayName: 'Upload Coverage to CodeAnt'
Important:
  • In Project → Pipelines → Library, add a secret variable named ACCESS_TOKEN with your personal access token or repo token.

How it works

  1. Setup environment The task automatically extracts organization, project, and repository information from Azure DevOps built-in variables.
  2. Download script The task fetches the coverage upload script (upload_coverage.sh) from the CodeAnt API endpoint.
  3. Upload coverage The script uploads your coverage report to CodeAnt AI for analysis and tracking.
  4. Pipeline feedback
    • Success: Coverage uploaded successfully
    • Failure: Upload fails due to authentication or file issues

Script Parameters

The upload_coverage.sh script accepts the following parameters:
ParameterFlagDescriptionRequiredExample
Access Token-t, --tokenAuthentication token for CodeAnt APIYes$(ACCESS_TOKEN)
Repository-r, --repoRepository name in organization/project/repository formatYesmyorg/myproject/myrepo
Commit SHA-c, --commitGit commit SHAYes$(Build.SourceVersion)
Coverage File-f, --filePath to coverage XML fileYescoverage.xml
Platform-p, --platformGit service providerYesazuredevops
Branch-b, --branchBranch nameNomain
Base URL-u, --urlBase URL for VCS serviceNohttps://dev.azure.com
Module Name-m, --moduleModule name for monorepo structureNobackend

Coverage Formats Supported

CodeAnt AI supports multiple coverage report formats:
  • Cobertura XML (most common, generated by coverage xml)
  • JaCoCo XML (Java projects)
  • Clover XML
  • lcov.info (JavaScript/TypeScript projects)

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.

Python Example

[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 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.