Skip to main content

Overview

This document shows how to use the CodeAnt Quality Gates pipe in your Bitbucket pipelines. Reference Repository: quality-gates-codeant

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 scan - you don’t need a Bitbucket access token or app password.

2. Configure Repository Variables

Before using the pipe, configure this repository variable in Repository Settings → Pipelines → Repository variables:
  • CODEANT_TOKEN - Your CodeAnt token (cdt_…)
Note: In the examples below the pipe expects a pipeline variable named ACCESS_TOKEN which is set from the repository variable; e.g. ACCESS_TOKEN: $CODEANT_TOKEN. This mapping is required so the container receives the token at runtime.

Basic Usage

Example 1: Run Quality Gates on Every Push

Example 2: Run Quality Gates on Pull Requests Only

Example 3: Run Quality Gates with Custom Configuration

Example 4: Multi-Stage Pipeline with Quality Gates

Example 5: Quality Gates with Debug Mode

Configuration Variables

How It Works

  1. The pipe fetches the quality gates script from the CodeAnt API
  2. It initiates a quality gate scan for your repository and commit
  3. It polls for results until the scan completes or times out
  4. If secrets or issues are detected, the pipeline fails
  5. If the quality gate passes, the pipeline continues

Execution Time Considerations

⏱️ Performance Options:
  • Default behavior (with result waiting): ~5-7 minutes
    • Triggers scan and waits for complete analysis results
    • Provides immediate feedback on secrets and security issues
    • Best for comprehensive CI/CD pipelines where you need instant validation
  • Custom timeout settings: Adjust based on repository size
    • Use TIMEOUT: "600" (10 minutes) for larger repositories
    • Use POLL_INTERVAL: "20" to reduce API polling frequency
    • Results can also be viewed in the CodeAnt dashboard
Tip: For faster PR checks on larger repositories, increase the timeout to avoid premature pipeline failures while the scan completes.

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

Troubleshooting

Pipeline Fails Immediately

Issue: Pipeline fails with “ACCESS_TOKEN is required but not set” Solution: Ensure you’ve set CODEANT_TOKEN in your repository variables.

Pipeline Times Out

Issue: Pipeline times out waiting for results Solution: Increase the TIMEOUT variable:

Connection Issues

Issue: Cannot connect to CodeAnt API Solution: Verify the API_BASE URL and check if you need to use a custom endpoint:

Support

License

MIT License - see LICENSE file for details## 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.