.gitlab-ci.yml file to provide automated vulnerability scanning and Merge Request enforcement.
Prerequisites
GitLab requires a secure token to authenticate with the Codepure API.- Navigate to API Tokens in your Codepure Dashboard.
- Click Generate New Token and copy the secret key.
- In your GitLab repository, go to Settings > CI/CD > Variables.
- Click Add variable.
- Set the Key to
CODEPURE_TOKEN. - Paste your token into the Value field. Ensure Mask variable is checked so it doesn’t appear in your pipeline logs.
Automated Setup (Recommended)
Codepure can automatically inject the required CI/CD template into your repository directly from the dashboard.- Go to Source Control in Codepure and click Configure Pipeline next to your GitLab repository.
- Set your vulnerability thresholds in the Policy Manager.
- Select your target branch under Integration Setup.
- Click Enable DevSecOps & Enforce Gates.
.gitlab-ci.yml file.
Manual Setup
If you already have a complex.gitlab-ci.yml file, you can easily include the Codepure template using a remote import to keep your code clean.
- Open your
.gitlab-ci.ymlfile. - Add the following configuration to the top of your file:
If you have custom stages defined in your GitLab pipeline, ensure you add
- codepure_security_scan to your stages: array block.How it Works
When a Merge Request is opened or code is pushed, GitLab will trigger thecodepure_devsecops_gate job.
- If the branch is configured as an Audit Branch, the job will exit with Code 3 (Warning), turning the pipeline yellow but allowing the merge to proceed.
- If the branch is an Enforcement Branch and vulnerabilities violate your policy, the job will exit with Code 1 (Fatal), turning the pipeline red and strictly blocking the Merge Request.

