Skip to Content
Get startedStep 3: build environmentBuild environment with GitLab

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

  1. In your GitLab repository, navigate to:
    Settings → CI/CD → Variables
  2. Click Add variable.
  3. Add the following secrets:
    • Cloudsmith Token
      • Key: CLOUDSMITH_TOKEN
      • Value: (paste the Cloudsmith token value)
    • Level CI Project Token
      • Key: LEVEL_CI_TOKEN
      • Value: (paste the Project token value)
  4. Make sure the “Masked and hidden” checkbox is checked.
  5. 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/cli

This 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:

level-ci.config.ts
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 Config

4. Update .gitlab-ci.yml

Add artifacts configuration to your e2e test stage so Level CI can access reports:

.gitlab-ci.yml
artifacts: paths: - level-ci-reports/

Then, add a new job for Level CI Accessibility Analysis:

.gitlab-ci.yml
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:

  1. Ensure your e2e tests pass locally.
  2. 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.

Last updated on