Installation
Before using CodeAnt Quality Gates in your Azure Pipelines, you need to install the CodeAnt extension from the Azure DevOps Marketplace:- Go to the Azure DevOps Marketplace and search for “CodeAnt AI” or directly download from here
- Click Get it free
- Select your Azure DevOps organization
- Click Install
CodeAntQualityGate@1 task will be available in all pipelines across your organization.
Repository Scenarios
CodeAnt Quality Gate supports multiple repository configurations in Azure DevOps:Scenario 1: Azure Repos + Azure DevOps Pipeline
For Azure Repos in Azure DevOps Services:azure-pipelines.yml
Note: The task automatically extracts repository information from these Azure DevOps built-in variables:
SYSTEM_TEAMPROJECT- Project nameBUILD_REPOSITORY_NAME- Repository nameBUILD_SOURCEVERSION- Commit SHA
Job token permissions
The job’s Build Service identity needs Read access to the repository. See Azure Pipelines job token permissions.Use a CodeAnt token as a fallback
If the built-in token is unavailable, create a CodeAnt token with the Codeant CI/CD role and repository access. Save it as a secret pipeline variable namedCODEANT_TOKEN and replace the input:
Scenario 2: Azure Repos (TFS / Azure DevOps Server – on-prem) + Azure DevOps Server (TFS) Pipeline
When your repository is hosted in an on-premise Azure DevOps Server (formerly known as Team Foundation Server / TFS), you need to explicitly pass all required parameters including the base URL.azure-pipelines.yml
Parameters for Azure DevOps Server (TFS)
Note: For on-premise Azure DevOps Server / TFS deployments, all parameters must be explicitly provided as environment variables may differ from Azure DevOps Cloud.
Scenario 3: GitHub Repository + Azure DevOps Pipeline
azure-pipelines.yml
Parameters for GitHub
Scenario 4: GitLab Repository + Azure DevOps Pipeline
azure-pipelines.yml
Parameters for GitLab
Scenario 5: Bitbucket Repository + Azure DevOps Pipeline
azure-pipelines.yml
Parameters for Bitbucket
Video Tutorial
Watch this video to learn how to integrate CodeAnt AI into your CI/CD pipelines:Azure Pipelines Workflow
Add the following to yourazure-pipelines.yml. It will trigger on every push to your repository and run quality gate checks to detect secrets and other security issues:
azure-pipelines.yml
With Optional Parameters
You can customize the timeout and polling interval:azure-pipelines.yml
How it works
-
Setup environment
Extract organization, project, and repository information from Azure DevOps built-in variables. Both currenthttps://dev.azure.com/{organization}/collection URLs and legacyhttps://{organization}.visualstudio.com/URLs are supported. -
Download script
We fetch the quality gates script (quality_gates.sh) from the CodeAnt API endpoint. -
Start scan
The script initiates a quality gate scan for your commit using the-o startoperation. -
Poll for results
The script polls for scan results using the-o resultsoperation with:- Timeout: 300 seconds (5 minutes)
- Poll interval: 15 seconds
-
Pipeline feedback
- Success: Quality gate passes when every enabled check passes
- Failure: Quality gate fails when any enabled check fails or the result times out, blocking the build
Quality Gate Checks
The quality gate performs comprehensive checks including:Security and Code Quality Checks
- Secret Detection: Scans for hardcoded secrets, API keys, passwords, and tokens
- SAST (Static Application Security Testing): Detects security vulnerabilities in source code
- SCA (Software Composition Analysis): Identifies vulnerabilities in third-party dependencies
- IaC (Infrastructure as Code): Scans infrastructure configuration files for security issues
- Duplicate Code Detection: Identifies code duplication to improve maintainability
- Analyzes only the changed lines since your merge base commit
- Uses high-confidence detection to minimize false positives
- Blocks the build if any issues are found
Best Practices
- Run on all branches: Quality gates should run on every push to catch issues early
- Block builds: Configure branch policies to require quality gate pipeline success before merging
- Review failures: When quality gates fail, review the detected issues immediately
- Keep tokens secure: Pass
$(System.AccessToken)directly; never commit token values - Use variable groups: If using the fallback, store
CODEANT_TOKENin an authorized variable group linked to each pipeline - Set appropriate timeouts: Adjust timeout values based on your repository size and complexity
- Monitor performance: Track how long quality gate checks take and optimize if needed
Troubleshooting
Task not found
If you see “Task ‘codeant-quality-gate’ not found”:- Ensure the CodeAnt extension is installed in your Azure DevOps organization
- Go to Organization Settings → Extensions to verify installation
- Check that the extension is enabled for your project
Quality gate times out
If the scan takes longer than expected:- Increase the timeout using
timeout: '600'(10 minutes) - Check if the CodeAnt service is operational
- Consider optimizing your repository size
- Review your network connectivity to the CodeAnt API
Authentication failures
If you seeHTTP 401, HTTP 403, or “Access token invalid”:
- For Azure Repos in Azure DevOps Services, pass
accessToken: $(System.AccessToken)from the running job. - Check that the job’s Build Service identity has Read access to the target repository and that job authorization scope permits access. See job token permissions.
- If using
CODEANT_TOKEN, check that the secret variable resolves, the token is active, and its Codeant CI/CD role and repository scope cover the target repository.
No results returned
If the scan completes but returns no results:- Check that quality gates are enabled for your repository in CodeAnt
- Verify the commit SHA is correct
- Ensure your Azure DevOps organization has proper integration with CodeAnt
- Check the CodeAnt dashboard to see if the scan was registered
Repository format issues
If you see “Invalid repository format” or “Required Azure DevOps variables not found”:- Verify that environment variables are being set correctly
- Check that
BUILD_REPOSITORY_NAME,BUILD_SOURCEVERSION,SYSTEM_TEAMPROJECT, andSYSTEM_TEAMFOUNDATIONCOLLECTIONURIare available - The task expects repository format:
organization/project/repository - Check the task’s
Azure DevOps URL format,Repository, andBase URLlog lines. These values are safe to share with support.
Legacy visualstudio.com organization URLs
Version 1.0.30 and later of the Marketplace extension automatically converts https://{organization}.visualstudio.com/ into the same repository identity used by https://dev.azure.com/{organization}/. The task log reports Azure DevOps URL format: legacy-cloud when this path is detected.
If an older installed extension produces a repository path containing https: or .visualstudio.com, update the CodeAnt extension under Organization Settings → Extensions. As a temporary workaround, set repo explicitly:
azure-pipelines.yml
Pipeline fails silently
If the pipeline exits without clear error:- Confirm the task is version
1.0.30or later. It reports network failures, HTTP status, masked token identity, service, repository, and provider base URL before exiting. - Do not enable shell tracing with
set -x; command tracing can expose secret arguments on some runners.
Extended Timeout for Large Repositories
For larger repositories that take longer to scan:azure-pipelines.yml
Windows Runner Configuration
If you’re using Windows runner (windows-latest) instead of Linux runner, make the following change:
Change Required
Update pool configuration:azure-pipelines.yml
Key Difference
On-Premise Deployment
If you are using a self-hosted CodeAnt instance, you can specify a custom API endpoint using theapiBase parameter:
azure-pipelines.yml
Note: The apiBase parameter is only required for on-premise deployments. Cloud users do not need to configure this.
With quality gates in place, every push will automatically be scanned for security issues, helping you maintain code security and compliance standards in your Azure DevOps repositories.
Token permission
If you authenticate with a CodeAnt API token (cdt_…) and 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.