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
Name | Description | Required | Default |
---|---|---|---|
ACCESS_TOKEN | GitLab token for authentication | Yes | - |
API_BASE | Base URL for CodeAnt API | No | https://api.codeant.ai |
TIMEOUT | Maximum time in seconds to wait for results | No | 300 |
POLL_INTERVAL | Time in seconds between polling attempts | No | 15 |
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: Add Pipeline Configuration
Copy the.gitlab-ci.yml
file from this repository to the root of your GitLab project.
Step 2: 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
- Value: Your GitLab PAT
- Type: Variable
- Environment scope: All
- Protect variable: ✓ (Recommended)
- Mask variable: ✓ (Recommended)
- Key:
- Click Add variable
Step 3: Commit and Push
Testing from Another Repository
To test this pipeline configuration in your own repository:- Clone or copy the
.gitlab-ci.yml
to your repository - Set up the
ACCESS_TOKEN
variable in your project settings - Push to trigger the pipeline:
- Create a merge request to test automatic scanning
- Modify the
variables
section 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:
GitLab CI/CD Variables Used
The pipeline automatically uses these GitLab-provided variables:Variable | Description |
---|---|
$CI_PROJECT_PATH | Project path (e.g., codeant-pipelines/quality-gates-gitlab) |
$CI_COMMIT_SHA | Current commit SHA |
$CI_DEFAULT_BRANCH | Default branch name (usually main or master) |
$CI_PIPELINE_SOURCE | Source that triggered the pipeline |
$CI_COMMIT_BRANCH | Current branch name |
$CI_JOB_STATUS | Job status (success/failed) |
Required Permissions
TheACCESS_TOKEN
requires the following permissions:
- API access - For CodeAnt API authentication
- read_repository - Read access to repository contents (if using GitLab PAT)
- read_api - Read API access (if using GitLab PAT)
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_BASE
URL is correct - Check network connectivity from GitLab runners to CodeAnt API
- Ensure API endpoint is accessible
- Verify
ACCESS_TOKEN
is set in CI/CD variables - Check token has not expired
- Ensure token has correct permissions
- Increase
TIMEOUT
value for larger repositories - Check CodeAnt API status
- Review scan logs for errors
- Verify
.gitlab-ci.yml
is 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