CodeAnt Quality Gate Scan for GitLab
This GitLab CI/CD pipeline runs CodeAnt quality gate scan with secret detection and code quality analysis. It integrates with your CI/CD pipeline and fails if secrets are detected or quality gates fail.Features
- 🔒 Secret detection and security scanning
- 📊 Code quality gate enforcement
- ⏱️ Configurable polling and timeout
- ✅ Pass/Fail pipeline status based on scan results
Variables
Self-hosted GitLab: The pipeline forwards your instance URL (
CI_SERVER_URL) to CodeAnt so the token is validated against the correct GitLab server. This happens automatically - no extra configuration is needed. If validation fails with 401 Access token invalid, confirm CI_SERVER_URL resolves to your GitLab instance, or set BASE_URL explicitly (e.g. https://gitlab.your-company.com).Usage
Quick Start (Recommended)
Add this to your.gitlab-ci.yml:
ACCESS_TOKEN variable in your GitLab project settings (Settings > CI/CD > Variables).
With Custom Job Name
With Multiple Stages
Setup Instructions
Step 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 withcdt_ and is shown only once). See API Tokens for the full walkthrough. This single token authenticates the scan - you don’t need a GitLab access token.
Step 2: Add Pipeline Configuration
Copy the.gitlab-ci.yml file from this repository to the root of your GitLab project.
Step 3: Configure CI/CD Variables
Add the requiredACCESS_TOKEN variable to your GitLab project:
- Go to Settings > CI/CD > Variables
- Click Add Variable
- Configure:
- Key:
ACCESS_TOKEN(this is the variable name the included template reads) - Value: Your CodeAnt token (
cdt_…) - Type: Variable
- Environment scope: All
- Protect variable: ✓ (Recommended)
- Mask variable: ✓ (Recommended)
- Key:
- Click Add variable
Step 4: Commit and Push
Testing from Another Repository
To test this pipeline configuration in your own repository:- Clone or copy the
.gitlab-ci.ymlto your repository - Set up the
ACCESS_TOKENvariable in your project settings - Push to trigger the pipeline:
- Create a merge request to test automatic scanning
- Modify the
variablessection in.gitlab-ci.yml - Add custom rules for when the pipeline should run
- Adjust timeout and polling intervals as needed
How It Works
- Checkout: GitLab automatically checks out your repository code
- Fetch Script: Downloads the quality gates scanning script from CodeAnt API
- Prepare Script: Decodes and prepares the script for execution
- Start Scan: Initiates the quality gate scan on CodeAnt servers
- Poll Results: Continuously polls for scan results until completion or timeout
- Report Status: Reports pass/fail status and fails the pipeline if issues are detected
Expected Output
When Quality Gate Passes:
When Quality Gate Fails:
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
GitLab CI/CD Variables Used
The pipeline automatically uses these GitLab-provided variables:Configuration Options
Variables
Customize these variables in.gitlab-ci.yml:
Pipeline Rules
Control when the pipeline runs:Allow Failure
To make the quality gate advisory (non-blocking):Troubleshooting
Common Issues
1. “Failed to fetch quality gates script”- Verify
API_BASEURL is correct - Check network connectivity from GitLab runners to CodeAnt API
- Ensure API endpoint is accessible
401 Access token invalid
- Verify
ACCESS_TOKENholds a valid CodeAnt token (cdt_…) that hasn’t been revoked - Ensure the token belongs to the same organization as the repository
- Self-hosted GitLab: the token is validated against the GitLab instance reported by
BASE_URL(default$CI_SERVER_URL). A 401 usually means CodeAnt validated against the wrong instance - confirmCI_SERVER_URLpoints to your GitLab server, or setBASE_URLexplicitly (e.g.https://gitlab.your-company.com)
- Increase
TIMEOUTvalue for larger repositories - Check CodeAnt API status
- Review scan logs for errors
- Verify
.gitlab-ci.ymlis in repository root - Check CI/CD is enabled for the project
- Review pipeline rules configuration
Debug Mode
To enable detailed logging, add debug commands:Advanced Usage
Multiple Quality Gates
Run different quality gates for different branches:Integration with Other Jobs
Chain the quality gate with other jobs:Support
For issues, questions, or contributions, please:- Documentation: https://docs.codeant.ai
- GitLab CI/CD: https://docs.gitlab.com/ee/ci/
- Issues: Contact your CodeAnt support team or create an issue in this repository
License
This project is licensed under the MIT License - see the LICENSE file for details. Repository: https://gitlab.com/codeant-pipelines/quality-gates-gitlab Powered by CodeAnt AI - Automated Code Quality and Security Analysis## 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.