Build environment with GitLab
Level CI integrates into your GitLab pipelines through a custom pipe. The main purpose of the pipe is to collect accessibility reports generated during e2e tests execution and to trigger analysis via Level CI API.
To build your environment:
1. Add an Environment Variable
- In your GitLab repository, navigate to:
Settings → CI/CD → Variables - Click Add variable.
- Add the following secrets:
- Cloudsmith Token
- Key:
CLOUDSMITH_TOKEN - Value: (paste the Cloudsmith token value)
- Key:
- Level CI Project Token
- Key:
LEVEL_CI_TOKEN - Value: (paste the Project token value)
- Key:
- Cloudsmith Token
- Make sure the “Masked and hidden” checkbox is checked.
- Click “Add variable”.
2. Install the Level CI CLI
Install the @level-ci/cli package in the root of your project:
npm install --save-dev @level-ci/cliThis CLI provides a command-line interface for scans and includes TypeScript types for configuration files.
3. Create a Configuration File
In the root of your project, create a level-ci.config.ts (or .js) file:
import type { Config } from '@level-ci/cli'
export default {
organization: 'your_organisation',
project: 'your_project',
token: process.env.LEVEL_CI_TOKEN,
reportPaths: ['./level-ci-reports'],
} satisfies Config4. Update .gitlab-ci.yml
Add artifacts configuration to your e2e test stage so Level CI can access reports:
artifacts:
paths:
- level-ci-reports/Then, add a new job for Level CI Accessibility Analysis:
level-ci-accessibility-analysis:
only:
- main
- merge_requests
image:
name: docker.levelaccess.net/level-ci-public/level-ci-gitlab:latest
entrypoint: ['']
script:
- level-ci⚠️ This is a minimal base configuration to run continuous accessibility analysis on your main branch and merge requests.
If you already have a pipeline, simply add this step to your existing .gitlab-ci.yml.
For a working example, check out our sample repository .
5. Verify Your Configuration
Before committing changes, validate the setup locally:
- Ensure your e2e tests pass locally.
- Run the following command in your terminal:
npx level-ci --verify --token=<your_project_token>6. Troubleshooting
If you encounter issues, refer to the troubleshooting guide.