# Visual regression testing in GitLab CI

> Run visual regression testing in GitLab CI: connect GitLab, upload screenshots from your pipeline and review diffs as commit statuses on merge requests.

Source: https://snapvisor.io/gitlab-ci

Guide

Keep your pipeline and your test runner. Connect GitLab to Snapvisor once, upload the screenshots from a GitLab CI job, and each build posts its result as a commit status on the matching merge request. Self-managed GitLab is supported.

## Connect GitLab to Snapvisor

Snapvisor talks to GitLab with a **personal access token** that has repository access. Add it in your team or account settings. Snapvisor updates commit statuses on behalf of the user who created the token, so use an account that should appear as the status author.

Only team admins can configure the GitLab connection. If you are not an admin, ask your team owner to set it up.

Once the token is set up, import a repository from GitLab and link it to a Snapvisor project. From then on every build posts its result as a commit status on the matching merge request.

Read more: [GitLab](https://snapvisor.io/docs/gitlab), [CI integration](https://snapvisor.io/docs/ci-integration).

## Self-managed GitLab

Running GitLab on your own infrastructure is supported. Configure the GitLab proxy URL for your instance so Snapvisor reaches your self-managed server instead of gitlab.com.

## Give the job the project token

Create a project in the Snapvisor app and copy its project token (`ARGOS_TOKEN`) from the project settings. Store it as a CI secret, never in the repository.

Tokenless authentication is documented for GitHub Actions only, so a GitLab job needs `ARGOS_TOKEN` in its environment. Set it as a CI/CD variable in your GitLab project settings.

## Capture screenshots with your test runner

GitLab CI only runs the command. Screenshots come from the adapter for your test runner, set up exactly as on its own guide: Playwright, Cypress, Storybook or Puppeteer. The adapter uploads when the run finishes, or you upload a folder with `@snapvisor/cli`.

.gitlab-ci.yml

```
# .gitlab-ci.yml
visual-tests:
  image: mcr.microsoft.com/playwright:v1.64.0-noble # match your @playwright/test version
  stage: test
  script:
    - npm ci
    - npm run build
    - npx playwright test # captures via argosScreenshot, uploads via the reporter
```

The job needs an image that has the Playwright browsers installed. The example uses Microsoft's official Playwright image; pick the tag that matches the `@playwright/test` version in your project, because the image and the package must agree.

A green GitLab job after the upload means the screenshots arrived, not that they are unchanged. The result is the commit status Snapvisor posts to the merge request, so look at that status before you merge.

## What the SDK reads from the job

When a job runs in GitLab CI (`GITLAB_CI` is `true`), the SDK recognizes it and reads these GitLab variables, so the build is tied to the right commit without any flags:

- `CI_COMMIT_SHA` for the commit.
- `CI_COMMIT_REF_NAME` for the branch.
- `CI_PROJECT_PATH` for the project path.
- `CI_PIPELINE_ID` as the build's nonce, the tag that parallel shards share.

Large suites can shard their uploads across jobs and be reviewed as one build.

Read more: [Parallel testing](https://snapvisor.io/docs/parallel-testing), [Access tokens](https://snapvisor.io/docs/tokens).

## What the first build does

The first build on your base branch has nothing to compare against, so it becomes the baseline and is approved automatically. Run it on a base branch that already looks right. Later builds are diffed against the last approved build on the base branch, and approving a change promotes it to the new baseline for that branch.

Read more: [Baseline builds](https://snapvisor.io/docs/baseline-build), [Review workflow](https://snapvisor.io/docs/review-workflow).

## Frequently asked questions

### Does Snapvisor work with GitLab merge requests?

Yes. Snapvisor uses a GitLab personal access token to update commit statuses, so each build posts its result on the matching merge request, the same way it does on GitHub pull requests.

### Can I use self-managed GitLab?

Yes. Configure the GitLab proxy URL for your instance so Snapvisor reaches your self-managed server instead of gitlab.com.

### Who can set up the GitLab connection?

Only team admins can configure it. If you are not an admin, ask your team owner.

### Can a GitLab job skip the project token?

No. Tokenless authentication is documented for GitHub Actions only, so a GitLab job sets ARGOS_TOKEN, your project token, as a CI/CD variable.

### Which GitLab CI variables does the SDK read?

When GITLAB_CI is true it reads CI_COMMIT_SHA for the commit, CI_COMMIT_REF_NAME for the branch and CI_PROJECT_PATH for the project path, and it uses CI_PIPELINE_ID as the nonce that parallel shards share.

### Does a green GitLab job mean nothing changed?

No. It means the screenshots arrived. The result is the commit status Snapvisor posts to the merge request, so check that status before you merge.

## Where to go next

[**Visual regression testing in GitHub pull requests**The same review loop on GitHub, with tokenless authentication.](https://snapvisor.io/visual-regression-testing-github) [**Visual regression testing guide**How the capture, compare and review loop works.](https://snapvisor.io/visual-regression-testing)

## Sources

Every command, package name and option on this page comes from the Snapvisor documentation and the published `@snapvisor` packages:

- [GitLab](https://snapvisor.io/docs/gitlab)
- [CI integration](https://snapvisor.io/docs/ci-integration)
- [SDKs](https://snapvisor.io/docs/sdks)
- [Getting started](https://snapvisor.io/docs/getting-started)
- [Baseline builds](https://snapvisor.io/docs/baseline-build)
- [Review workflow](https://snapvisor.io/docs/review-workflow)
- [Parallel testing](https://snapvisor.io/docs/parallel-testing)
- [Access tokens](https://snapvisor.io/docs/tokens)

## Try Snapvisor free

[Start free](https://app.snapvisor.io/signup) [Getting started guide](https://snapvisor.io/docs/getting-started) [All SDKs](https://snapvisor.io/docs/sdks) [See pricing](https://snapvisor.io/pricing)

## Related pages

Guides [How visual regression testing works](https://snapvisor.io/visual-regression-testing) [Self-hosted visual regression testing](https://snapvisor.io/self-hosted-visual-regression-testing) [Visual regression testing in GitHub pull requests](https://snapvisor.io/visual-regression-testing-github) [Snapvisor MCP server](https://snapvisor.io/mcp)

Test runner and CI setup [Playwright visual testing setup](https://snapvisor.io/playwright) [Storybook visual testing setup](https://snapvisor.io/storybook) [Cypress visual testing setup](https://snapvisor.io/cypress) [Puppeteer visual testing setup](https://snapvisor.io/puppeteer)

Compare Snapvisor [Snapvisor vs Percy](https://snapvisor.io/compare/percy) [Snapvisor vs Chromatic](https://snapvisor.io/compare/chromatic) [Snapvisor vs Applitools](https://snapvisor.io/compare/applitools) [Snapvisor vs Argos](https://snapvisor.io/compare/argos) [Snapvisor vs Lost Pixel](https://snapvisor.io/compare/lost-pixel) [Snapvisor vs Happo](https://snapvisor.io/compare/happo) [Snapvisor vs Playwright snapshots](https://snapvisor.io/compare/playwright) [Visual regression testing pricing compared](https://snapvisor.io/visual-regression-testing-pricing) [Alternatives to other visual testing tools](https://snapvisor.io/alternatives)

Free tools [Image diff checker](https://snapvisor.io/tools/image-diff) [Screenshot calculator](https://snapvisor.io/tools/screenshot-calculator)
