The Simplest Way to Make Cypress and GitLab CI Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Using cypress and gitlab ci together lets teams run automated browser tests on every code push. GitLab starts a clean runner and runs Cypress against your web app before code merges. This workflow catches broken pages and failed logins before users ever see them. Teams get fast feedback in their merge requests and keep broken code out of production. How cypress and gitlab ci share keys and data GitLab stores secret values in project settings and passes them to the runner at start time. Cypre

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Using cypress and gitlab ci together lets teams run automated browser tests on every code push. GitLab starts a clean runner and runs Cypress against your web app before code merges.

This workflow catches broken pages and failed logins before users ever see them. Teams get fast feedback in their merge requests and keep broken code out of production.

How cypress and gitlab ci share keys and data

GitLab stores secret values in project settings and passes them to the runner at start time. Cypress reads those values to log in to test accounts and call backend services.

First, a developer pushes code to a branch. Next, GitLab reads the pipeline file and starts a container with a browser and Cypress installed. The runner builds or reaches the web app, then runs the test files one by one.

During each run, Cypress acts like a real user in a real browser. It clicks buttons, fills forms, and checks page text. When a test finishes, the runner saves screenshots, videos, and test logs back to GitLab.

Permissions matter at every step of this flow. The runner needs a key to pull container images and read code. Cypress needs test user keys to log in to the app under test. Keeping these two sets of keys separate prevents leaks during test runs.

Common failure modes and how to scope roles

Many teams use one shared admin account for all browser tests. When ten pipelines run at once, those tests overwrite each other's data and fail at random. Shared admin keys also create a big security risk if a test log leaks them.

Broad runner tokens cause a second common problem. If a pipeline key can read production databases, a bad script in a feature branch can steal data. Unlogged database queries during test seed steps also make it hard to track who changed what.

GitLab CI Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, give each test job a narrow role with only the rights it needs. Use separate test accounts for parallel jobs so runs never clash. Lock secret variables to protected branches so random forks cannot read them.

Scope network paths between the runner and your test backend as well. Allow the runner to reach only the staging app and a dedicated test database. Block all traffic from test runners to production hosts.

Mask sensitive data in test databases and logs before tests run. For example, masking rewrites emails, phone numbers, card numbers, and national IDs in query results. This keeps real user records out of test screenshots and failure logs.

Running faster pipelines with parallel test jobs

Browser tests take a long time when they run one after another on one machine. A suite of fifty tests can block a merge request for half an hour. Teams then start skipping tests to ship faster, which defeats the whole point.

GitLab lets you split a test job across several runners at the same time. Each runner takes a small slice of the spec files and runs them in parallel. Your team gets the full test result in a few minutes instead of thirty.

When you run parallel jobs, keep your test state clean across every container. Each job should create its own test rows and clean them up when done. Clear browser state before each spec so old cookies never break the next check.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Why do my Cypress tests pass on my laptop but fail in GitLab?

Cloud runners often have less memory and slower CPUs than a developer laptop. Fix this by waiting for network calls to finish instead of using fixed sleep timers.

How should we store login secrets for Cypress in GitLab?

Store test passwords in GitLab masked project variables rather than in your code files. Scope those variables to specific branches so untrusted merge requests cannot print them in logs.

Where do we find screenshots when a GitLab test job fails?

Tell your pipeline job to save the Cypress output folders as job artifacts on failure. You can then download or view the screenshots and videos right from the GitLab job page.

The query runs. The emails stay hidden.