Cypress CI/CD best practices with Cypress Cloud center on structuring test runs for parallelization, managing recorded artifacts efficiently, and using the dashboard to diagnose flaky tests. You configure your CI provider to run Cypress with the `cypress run` command, add the `–record` flag to upload results to Cypress Cloud, and set a `CYPRESS_RECORD_KEY` environment variable to authenticate. The payoff is faster feedback, a centralized history of test runs, and a clear view of failures across your entire test suite.
Why Cypress Cloud Matters in CI/CD
Cypress Cloud (formerly Cypress Dashboard) is the hosted service that stores your test recordings, screenshots, videos, and run metadata. When you run tests in CI, you get a link to a run page that shows which specs passed or failed, how long each took, and the exact error messages. This is especially valuable in CI because you cannot easily watch tests execute on a headless server. The cloud also provides analytics—like flaky test detection and run duration trends—that help you decide whether to split your suite differently or address a recurring failure.
Without Cypress Cloud, you still can run Cypress in CI, but you lose the historical record and the ability to group parallel runs. For teams with more than a few specs, the cloud becomes a practical necessity for debugging and for tracking test health over time.
Setting Up CI for Cypress: The Basics
Before you add Cypress Cloud, you need a working CI pipeline. The typical steps are:
- Install dependencies: `npm ci` (or `yarn install –frozen-lockfile`) to get an exact dependency set.
- Cache the Cypress binary and npm cache to speed up subsequent runs.
- Run the tests: `npx cypress run` (or `npx cypress run –record` once you have the key).
- Upload the `cypress/videos` and `cypress/screenshots` folders as CI artifacts if you are not using Cypress Cloud.
Most CI providers (GitHub Actions, GitLab CI, CircleCI, Jenkins) have official Cypress examples. The key is to ensure the CI environment has the same browser versions that you use locally. For example, if you use Chrome 120 locally, pin that version in your CI image to avoid rendering differences.
Best Practices for Recording to Cypress Cloud
Recording to Cypress Cloud is more than just adding a flag. Here are the practices that make the recorded data useful:
- Set the record key as a secret. In CI, store `CYPRESS_RECORD_KEY` in the provider’s secret manager, never in your repository. If you commit it, anyone with repo access can record to your project and consume your test minutes.
- Group parallel runs. Use the `–group` flag to label runs (e.g., `–group ‘chrome’` or `–group ‘smoke’`) so the cloud can aggregate results from multiple machines into one logical run.
- Tag runs for release versions. Use `–tag ‘release-1.2.3’` to associate a run with a code version. This makes it easy to see which commit introduced a failure.
- Set a build ID. Use `–ci-build-id` to tie parallel machines together. Most CI providers have an environment variable for the build number; pass it through so Cypress Cloud can group them.
- Turn off video for large suites. Video recording is useful for debugging, but it multiplies storage and upload time. Consider setting `video: false` in your config for routine runs, and enable it only when you need to investigate a specific failure.
Parallelization: How to Split Tests Effectively
Cypress Cloud’s parallelization works by splitting spec files across multiple CI machines. You do not need to manually shard your specs; the service does it for you. To use it, you must have a Cypress Cloud account, and you must pass the `–parallel` flag along with `–record`. Each CI job runs the same command, and the cloud coordinates which machine runs which spec.
For this to work well, your specs should be relatively balanced in duration. If you have one spec that takes 10 minutes and ten specs that take 1 minute each, the parallel run will still take about 10 minutes because the long spec cannot be split further. In that case, consider splitting the long spec into multiple smaller specs or using Cypress’s `cy.session()` to reduce repeated login overhead.
Another practical tip: set a reasonable number of parallel machines. The default is usually 1, and you pay for each machine that runs. Start with 2-3 machines and measure the wall-clock time. Beyond a certain point, the overhead of coordinating machines outweighs the time saved.
Handling Flaky Tests and Retries
Cypress Cloud has a built-in retry feature that can mask flaky tests. You configure retries in your `cypress.config.js` file:
module.exports = {
e2e: {
retries: {
runMode: 2,
openMode: 0
}
}
}
This retries a failed test up to 2 times when running in CI. The cloud will show the final result, and you can see the retry history in the run details. While retries help reduce false failures, they can hide real issues if the test is truly flaky. Use the cloud’s “Flaky Tests” analytics to identify tests that fail on the first attempt but pass on a retry. For those, investigate the root cause—often a timing issue, a race condition, or a dependency on external data—rather than just increasing retries.
A common misconception is that retries are a substitute for fixing flaky tests. They are not; they are a stopgap. Cypress Cloud will show you a flake rate per test, which you can use to prioritize fixes.
Common CI/CD Problems and How to Solve Them
Even with best practices, you will hit issues. Here are the most frequent ones and their fixes:
- Record key not found. The `CYPRESS_RECORD_KEY` environment variable is not set. Check that you are passing it correctly in your CI provider’s configuration.
- Parallel runs not grouping. You forgot to pass `–ci-build-id`. Without it, each machine starts a separate run.
- Out of memory. Cypress can consume a lot of RAM, especially with many specs. Increase the CI machine’s memory or limit the number of parallel processes with `–parallel –ci-build-id` and a lower number of machines.
- Timeout on `cy.visit()`. The application under test is slow to start. Increase the `defaultCommandTimeout` or use `cy.intercept()` to stub network requests that are not essential.
- Video uploads taking too long. Disable video for routine runs, or set `videoUploadOnPasses: false` to only upload videos for failing tests.
Comparing Cypress Cloud with Alternatives
Cypress Cloud is not the only option for recording and analyzing test runs. Some teams use CI artifacts (e.g., uploading videos and screenshots) and rely on the CI provider’s log viewer. This is free but lacks the aggregated analytics and parallelization coordination. Other tools like Sauce Labs or BrowserStack offer cloud testing but are more focused on cross-browser testing, not just Cypress. There are also open-source alternatives like ReportPortal or Allure that can aggregate results, but they require more setup and do not provide the same level of Cypress-specific integration.
For most teams, the choice comes down to whether you need parallelization and historical analytics. If your suite is small (under 10 specs) and runs in under 5 minutes, you can skip the cloud entirely. If you have a large suite or a team that needs to debug failures without digging through CI logs, the cloud is worth the cost.
Costs and Limits of Cypress Cloud
Cypress Cloud has a free tier that includes a limited number of test results per month (typically 500 results, which means 500 spec runs, not individual tests). Beyond that, you pay per test result. The paid plans also offer more parallelization and longer data retention. For open-source projects, Cypress offers free access to the cloud. Check the current pricing on the Cypress website, as it changes over time.
One important limit: the free tier only keeps data for 30 days. If you need a longer history for trend analysis, you need a paid plan. Also, the number of parallel machines is capped on the free tier (usually 1), so you cannot parallelize without paying.
Frequently Asked Questions
Do I need Cypress Cloud to run Cypress in CI?
No. You can run Cypress in CI without the cloud by just executing `cypress run`. You will get the results in the CI logs, and you can upload videos and screenshots as artifacts. The cloud adds value through parallelization, historical analytics, and a web UI for debugging.
How do I get my CI build ID for Cypress Cloud?
Each CI provider has a built-in environment variable. For example, GitHub Actions uses `GITHUB_RUN_ID`, GitLab CI uses `CI_PIPELINE_ID`, and CircleCI uses `CIRCLE_BUILD_NUM`. Pass that variable to the `–ci-build-id` flag, e.g., `–ci-build-id $GITHUB_RUN_ID`.
Can I use Cypress Cloud with a self-hosted CI like Jenkins?
Yes. As long as your Jenkins agent can reach the internet and has the `CYPRESS_RECORD_KEY` set, you can use all the cloud features. The only requirement is that the agent can upload the results.
Why is my parallel run not any faster?
The most likely reason is that you have a few long-running specs that dominate the total time. Check the spec duration breakdown in the cloud. If one spec takes 8 minutes and the rest take 1 minute, the run will take about 8 minutes regardless of how many machines you add. Split that spec into smaller ones.
What does “test result” mean in Cypress Cloud billing?
A test result is one spec file run. If you have 100 specs and run them once, that is 100 test results. Retries count as additional results. So a flaky test that fails twice and passes once will consume 3 results for that spec.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Secure Boot Battlefield 6 ASUS: Fix & Enable Guide
- Best Tech Websites to Follow for Pros & Beginners
- Second Wind Quest Walkthrough: Where Winds Meet6.00 min/km
- Enshrouded Weapon Upgrade Guide: How to Improve Gear5.00 min/km
- Connect Phone to Controller for Cloud Gaming
- Python Search Highlighting: Snippets & Matches