QA How-To
Cypress Cloud Smart Orchestration Setup: Step-by-Step Guide
Complete this Cypress Cloud Smart Orchestration setup to record tests, balance specs across CI runners, prioritize failures, and cancel broken runs in CI.
18 min read | 2,792 words
TL;DR
Connect Cypress to Cloud, store the record key as a CI secret, and run the same spec set on multiple workers with --record --parallel. Cypress Cloud then assigns specs one at a time using historical durations, while optional prioritization and auto cancellation improve failure feedback.
Key Takeaways
- Connect the repository with a committed projectId and a secret CYPRESS_RECORD_KEY.
- Start identical Cypress jobs with --record and --parallel so Cloud can assign specs dynamically.
- Use one CI build ID across workers and a unique group name for each browser or test lane.
- Let historical spec duration data drive load balancing instead of maintaining static shards.
- Enable spec prioritization and auto cancellation only after baseline recording works.
- Verify orchestration in the Cypress Cloud Machines, Timeline, and Run Properties views.
A reliable cypress cloud smart orchestration setup connects your project to Cypress Cloud, starts the same recorded run on multiple CI workers, and lets Cloud distribute spec files using historical duration data. The result is dynamic load balancing without a hand-maintained shard list.
This tutorial builds that workflow in GitHub Actions, then adds grouping, spec prioritization, and auto cancellation. For the architectural context behind spec boundaries, isolation, and CI design, read the Cypress Modern Test Architecture Complete Guide.
You will use a small TypeScript project and a four-runner matrix. The same principles apply to GitLab CI, CircleCI, Buildkite, Jenkins, and other providers that can launch concurrent workers with a shared build identifier.
What You Will Build
By the end, you will have:
- A Cypress project linked to Cypress Cloud through
projectId. - A protected
CYPRESS_RECORD_KEYavailable only to CI. - Four GitHub Actions runners requesting work from one recorded run.
- Automatic duration-aware spec load balancing.
- A named browser group and stable CI build identity.
- Optional spec prioritization and auto cancellation with visible proof that each feature ran.
The important mental model is a shared queue, not four fixed buckets. Every worker reports the same discovered spec list. Cypress Cloud gives an available worker the next spec, using recent duration estimates to start expensive specs early and keep machines occupied.
| Approach | Assignment | Adapts to duration changes | Main tradeoff |
|---|---|---|---|
| Static CI shards | Your pipeline fixes files to shard numbers | No | Simple, but requires maintenance and can leave runners idle |
| Cypress Cloud parallelization | Cloud assigns the next whole spec to a free worker | Yes | Requires recorded runs and Cloud connectivity |
| One serial runner | Cypress executes specs on one machine | Not applicable | Lowest setup complexity, longest feedback for larger suites |
Prerequisites
Use Node.js 20 or 22 LTS, npm, Git, a GitHub repository, and a Cypress Cloud organization where you can create a project. The examples use TypeScript and cypress-io/github-action@v7. Pin your own application dependencies through package-lock.json; do not depend on whatever version happens to be newest during a CI run.
Start in an existing web application or create a disposable one. Install Cypress locally:
npm install --save-dev cypress
npx cypress verify
npx cypress version
Your application needs a deterministic CI start command. This tutorial assumes npm run dev -- --host 0.0.0.0 serves the app at http://localhost:5173. Adjust baseUrl, start command, and port together if your project differs.
Before continuing, confirm npx cypress verify exits successfully and your repository has at least two independent spec files. Parallelization is file-based. One huge spec cannot be divided between workers while it is running.
Step 1: Create the Cypress Cloud Smart Orchestration Setup Baseline
Create a minimal configuration with a placeholder for the six-character Cloud project ID. Cypress Cloud generates the real value when you set up recording.
// cypress.config.ts
import { defineConfig } from 'cypress'
export default defineConfig({
projectId: 'a7bq2k',
e2e: {
baseUrl: 'http://localhost:5173',
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'cypress/support/e2e.ts',
},
retries: {
runMode: 2,
openMode: 0,
},
video: true,
})
Create the support file and two smoke specs:
// cypress/support/e2e.ts
// Add shared commands or global hooks here only when every spec needs them.
// cypress/e2e/home.cy.ts
describe('home', () => {
it('loads the application', () => {
cy.visit('/')
cy.location('pathname').should('eq', '/')
cy.get('body').should('be.visible')
})
})
// cypress/e2e/navigation.cy.ts
describe('navigation', () => {
it('has at least one link or button', () => {
cy.visit('/')
cy.get('a,button').should('have.length.greaterThan', 0)
})
})
Run the application in one terminal, then run npx cypress run in another.
Verify: Both spec names appear in terminal output and the run completes without attempting to contact Cypress Cloud. If the page never loads, fix the application start command or baseUrl before adding Cloud. Smart orchestration cannot correct an unreachable test target.
Step 2: Connect the Project and Protect the Record Key
Open Cypress with npx cypress open, choose the Runs area, sign in, and select or create your Cypress Cloud organization and project. Cypress writes the generated projectId into cypress.config.ts. Commit that ID because it identifies the Cloud project but does not authorize recorded runs.
The Record Key is different. It authorizes writes to the Cloud project and must remain secret. In GitHub, open the repository, choose Settings, Secrets and variables, Actions, then create a repository secret named CYPRESS_RECORD_KEY. Paste the key shown by Cypress Cloud. Never put it in cypress.env.json, a committed workflow value, a screenshot, or a command copied into a public log.
Test recording from a trusted shell without placing the value in shell history:
CYPRESS_RECORD_KEY='<your-record-key>' npx cypress run --record
For routine work, inject the variable through a secret manager rather than typing it. CYPRESS_RECORD_KEY and the optional CYPRESS_PROJECT_ID are operating-system variables understood by the recording client. They are not ordinary test values and should not live in the Cypress env configuration.
Verify: Cypress Cloud shows a new run with both specs. In the run details, confirm the project and commit metadata are correct. If Cloud reports an invalid key or project mismatch, compare the config projectId with the selected Cloud project and rotate an exposed key immediately.
Step 3: Add One Recorded GitHub Actions Runner
Establish a serial recorded workflow before multiplying workers. This separates application startup, dependency, and secret problems from orchestration problems.
# .github/workflows/cypress.yml
name: Cypress Cloud
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
cypress-run:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Cypress
uses: cypress-io/github-action@v7
with:
build: npm run build
start: npm run dev -- --host 0.0.0.0
wait-on: http://localhost:5173
wait-on-timeout: 120
record: true
browser: chrome
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
The maintained action installs locked dependencies, builds, starts the server, waits for it, and invokes Cypress. Keep the secret scoped to the step that needs it. Pull requests from forks do not receive repository secrets by default, which is safer than exposing a record key to untrusted code. Design a separate non-recording fork workflow if public contributions need checks.
Verify: Push a branch in the same repository. The Actions job should pass, and Cypress Cloud should show one machine in the run. Confirm the browser is Chrome and the run links to the expected commit. Do not add a matrix until this baseline is green.
Step 4: Enable Parallelization and Automatic Load Balancing
Turn the job into a four-worker matrix and set parallel: true. Every matrix copy checks out the same commit, discovers the same specs, and joins the same Cloud run through GitHub Actions metadata.
name: Cypress Cloud Parallel
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
cypress-run:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
container: [1, 2, 3, 4]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Cypress in parallel
uses: cypress-io/github-action@v7
with:
build: npm run build
start: npm run dev -- --host 0.0.0.0
wait-on: http://localhost:5173
wait-on-timeout: 120
record: true
parallel: true
browser: chrome
group: UI Chrome
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
fail-fast: false prevents GitHub from canceling sibling matrix jobs when one fails. Cypress Cloud needs the participating machines to finish reporting their assigned work. The container value creates four identical jobs; it does not select a fourth of the specs. Cloud performs the selection.
Load balancing activates automatically with recorded parallel runs. Cloud predicts each whole spec's duration from recent history, generally starts longer specs earlier, and gives another spec to a worker when that worker becomes free. Initial runs have limited history, so judge the distribution after several representative executions.
Verify: Open the recorded run, select Specs, then Machines. You should see up to four machines under UI Chrome, with each spec executed exactly once across the group. With only two specs, some workers will have no useful work. Add runners only when the suite has enough spec-level work to keep them occupied.
Step 5: Make Run Identity and Groups Explicit
Cypress recognizes build identifiers for common CI providers, including GitHub Actions through its environment metadata. Explicit identity is still useful in custom CI or when separate commands must join one logical run. All participating workers must send the same build ID, commit, project ID, group, browser, and discovered spec set.
The equivalent direct CLI command is:
npx cypress run \
--record \
--parallel \
--browser chrome \
--group 'UI Chrome' \
--ci-build-id "$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT"
In a custom CI system, define a build identifier that is unique per pipeline attempt but identical across its workers. Do not use a random value generated independently on each machine. That creates separate Cloud runs, so workers cannot share a queue. Conversely, reusing yesterday's ID can collide with an already completed run.
Groups label distinct lanes inside one run. A Chrome lane and Firefox lane can share a build ID, but they need unique group names such as UI Chrome and UI Firefox. Group names do not replace build identity. They make results understandable and prevent incompatible invocations from being treated as the same lane.
Verify: In Cypress Cloud, inspect the run details for one shared CI build ID and expand the Machines view. Confirm all expected workers sit beneath one group. If four jobs produced four runs, identity differs. If Cloud reports a group already used with different settings, make browser and group naming consistent.
Step 6: Prepare Specs for Effective Orchestration
Cypress distributes files, not individual it() blocks. A 20-minute checkout spec remains a 20-minute lower bound even if seven other workers become idle. Use the Cloud Bar Chart, Timeline, and slow-test analytics to find dominant specs, then split a broad workflow along independent business boundaries.
For example, replace one oversized checkout.cy.ts with focused files:
cypress/e2e/checkout/
address-validation.cy.ts
payment-declines.cy.ts
saved-card.cy.ts
guest-checkout.cy.ts
Each spec must create the state it needs. Use API setup, seeded data, or isolated test users instead of depending on another spec to run first. Parallel run order is intentionally not guaranteed. If a workflow needs several users or sessions, apply the patterns in Cypress test isolation for multi-user workflows.
Do not split files solely to make their test counts equal. Duration is what constrains completion. Keep meaningful scenarios together, observe real recorded duration, and split the few files that create a long tail. The historical-duration spec splitting tutorial shows how to turn Cloud evidence into better spec boundaries.
Verify: Compare several passing runs in the Machines or Timeline view. Healthy balancing means workers remain active and finish near one another, allowing for normal startup variance. If one worker continues far beyond all others, inspect its last spec and split that bottleneck if the scenarios can remain isolated.
Step 7: Enable Prioritization and Auto Cancellation Safely
Once baseline recording and parallelization are stable, open Cypress Cloud Project Settings and find Smart Orchestration. Enable Spec Prioritization if your plan provides it. It moves specs that failed in the previous relevant run toward the front while retaining duration-aware balancing for the rest. It does not guarantee a fixed global order.
Auto Cancellation stops remaining work after a failure threshold. You can configure it in Cloud, or pass a threshold on a recorded CLI run when supported by your plan and policy:
npx cypress run \
--record \
--parallel \
--group 'UI Chrome' \
--auto-cancel-after-failures 3
Choose the threshold deliberately. A value of one gives fast feedback but may hide independent failures. A higher value gathers more diagnostic signal before saving runner time. Also remember retries: cancellation policy should reflect how your team interprets final test failures, not merely a transient assertion.
To test prioritization, allow a disposable spec to fail in one branch run, then rerun the same branch context after a harmless commit. Remove the intentional failure afterward. To test cancellation, use a temporary branch with more failing specs than the threshold and ensure no production deployment depends on that experiment.
Verify: Open Run Properties and check the Smart Orchestration status. Applied prioritization identifies the prior run used, and prioritized specs show the orchestration indicator in the Specs timeline. A canceled run should state that auto cancellation stopped remaining work. A generic CI cancellation is not proof of the Cloud feature.
Troubleshooting
--parallel can only be used when recording -> Add --record and provide a valid CYPRESS_RECORD_KEY. Parallel orchestration depends on Cloud coordination and cannot operate as a purely local flag.
Cloud cannot determine a unique CI build ID -> Use a natively recognized CI variable or pass --ci-build-id. Ensure the value is shared by every worker in one attempt and changes for the next attempt.
Matrix jobs appear as separate Cloud runs -> Compare project ID, commit metadata, build ID, browser, group, and spec discovery. A random per-worker ID or different checkout SHA prevents workers from joining the same run.
Some workers execute no specs -> The suite has fewer schedulable spec files than workers, jobs joined too late, or one file dominates duration. Reduce concurrency, make workers start together, and split only the slow independent specs.
The server is unavailable in some matrix jobs -> Every hosted runner is a separate machine. Each job must install, build, start, and wait for its own application, or target a stable shared test environment. A server started in one job is not available through another job's localhost.
Recorded fork pull requests fail -> GitHub withholds repository secrets from untrusted forks. Keep that boundary. Run a non-recording command for forks, or require an authorized maintainer workflow after reviewing the code. Never switch to a privileged trigger that executes untrusted code with the record key.
Where To Go Next
Return to the complete Cypress modern test architecture guide to place orchestration inside a wider strategy for isolation, commands, data, and CI feedback.
Then improve the two inputs that most affect orchestration quality:
- Use historical spec durations to split Cypress tests when one file controls the critical path.
- Apply multi-user Cypress test isolation patterns before allowing workflows to execute in any order.
- Build typed, retryable abstractions with the Cypress query commands TypeScript tutorial so shared commands preserve Cypress's query behavior.
Treat machine count as a measured tuning decision. Review passing-run duration, time saved, machine utilization, and the longest spec. More workers help only while enough independent specs remain in the shared queue.
Interview Questions and Answers
Q: What activates load balancing in Cypress Cloud?
A recorded run with parallelization activates it. Multiple CI machines invoke Cypress with the same run identity and spec set, then Cloud assigns whole specs dynamically using duration estimates.
Q: Why must every worker discover the same specs?
Cloud coordinates a shared queue from the participating machines' spec information. Different patterns or checkouts make the run inconsistent and can cause grouping errors or missing coverage. Filtering belongs in a clearly named, consistent group.
Q: Is the record key safe to commit because projectId is committed?
No. The project ID identifies the project and is commonly committed. The Record Key authorizes recorded writes, so store it in a CI secret manager and rotate it if exposed.
Q: How does a CI build ID differ from a group name?
The build ID links machines and groups into one logical run. A group labels one lane, such as Chrome UI tests, within that run. Workers in the same lane need the same build ID and group name.
Q: Why can adding workers stop improving run time?
Cypress schedules whole spec files. Once there are too few remaining specs, or one very slow spec defines the critical path, additional workers wait idle. Split the bottleneck or reduce excess concurrency.
Q: What does spec prioritization change?
It moves previously failing specs toward the front to shorten feedback. It does not split specs, fix flaky tests, or replace load balancing for the remaining queue.
Best Practices for Cypress Cloud Smart Orchestration Setup
- Prove one recorded runner before enabling a matrix.
- Commit
projectId, but protect and rotate the Record Key. - Use
fail-fast: falsefor parallel matrix workers. - Keep run identity stable across workers and unique across attempts.
- Make every spec independently runnable in any order.
- Measure duration across representative passing runs before changing concurrency.
- Split critical-path specs by business behavior, not arbitrary test count.
- Keep forked code away from workflows that expose trusted secrets.
- Verify Cloud feature status instead of inferring it from shorter wall-clock time.
Review the workflow as an operating system for test feedback, not a one-time YAML task. Assign an owner for the Cloud project, document who can rotate Record Keys, and keep the CI action version visible in dependency maintenance. When the application start command or build output changes, validate the serial recording path before investigating the scheduler.
Keep groups purposeful. A group should represent a stable execution lane with a consistent browser, spec pattern, and configuration. Avoid creating a new group for every matrix index because that prevents the workers from sharing one queue. Use tags for useful run classification when appropriate, and use groups for invocations that truly differ.
Reassess concurrency after meaningful suite changes. Adding many short specs can make another worker useful, while consolidating tests or introducing one slow end-to-end journey can reduce parallel efficiency. Compare several normal passing runs because a failed or canceled run does not represent the complete workload. Track the critical path, not just the average duration of individual tests.
Finally, keep correctness independent of scheduling. Never rely on alphabetical file order, a user created by another spec, or a cleanup hook on another machine. A balanced queue is deliberately nondeterministic. If every spec can run alone, in a different order, and at the same time as its neighbors, orchestration can optimize speed without changing the meaning of the suite.
Conclusion
A successful cypress cloud smart orchestration setup is mostly about consistent inputs. Connect the right project, protect the Record Key, start equivalent workers under one build identity, and let Cypress Cloud schedule independent spec files from a shared queue.
Begin with one recorded job, expand to a measured matrix, then enable prioritization and cancellation after the baseline is observable. Use Cloud's Machines and Timeline views to guide spec splitting and runner count, and keep the suite isolated so dynamic order never changes correctness.
Interview Questions and Answers
How does Cypress Cloud distribute specs during a parallel run?
Each available worker asks Cypress Cloud for work. Cloud uses recent per-spec duration estimates to assign whole specs, generally prioritizing longer work so machines remain utilized. When a worker finishes, it requests another spec from the shared queue.
What are the minimum inputs for recorded Cypress parallelization?
The project needs a valid projectId and Record Key, and the command needs recording plus parallelization enabled. Participating workers must also resolve to the same CI build identity and discover a consistent spec set. Multiple concurrent machines are needed to gain a speed benefit.
Why is CYPRESS_RECORD_KEY treated differently from projectId?
The projectId identifies the Cypress Cloud project and is safe to keep in source control in most teams. The Record Key authorizes clients to create recorded runs. Exposing it can allow unauthorized usage and data, so it belongs in a secret manager and should be rotated after disclosure.
What problem does --ci-build-id solve?
It tells Cypress Cloud which machine invocations belong to one logical CI attempt when automatic provider detection is unavailable or unsuitable. The value must be identical across workers in that attempt and unique across separate attempts. A per-worker random value breaks coordination.
How would you diagnose poor parallel efficiency?
Inspect the Machines and Timeline views for idle gaps and identify the last-running specs. Check whether workers joined at similar times, then compare the longest spec with total run duration. Split isolated bottleneck specs or reduce worker count when the suite lacks enough schedulable files.
How do spec prioritization and auto cancellation complement load balancing?
Load balancing distributes work to reduce completion time. Spec prioritization moves previously failing specs earlier to accelerate feedback, while auto cancellation stops remaining work after a configured failure threshold. Together they can surface persistent failures early and avoid low-value execution.
Frequently Asked Questions
Does Cypress Cloud Smart Orchestration require multiple machines?
Recording works on one machine, but parallel load balancing provides practical value only with multiple concurrent workers and multiple spec files. Start with one machine to validate recording, then add workers based on suite size and measured utilization.
Do I need to split Cypress specs manually for Cloud parallelization?
You need multiple spec files, but you do not assign those files to fixed workers. Cypress Cloud assigns whole specs dynamically. Manually split only oversized specs that create a long tail after other workers become idle.
Should the Cypress projectId be stored as a secret?
The projectId is normally committed in cypress.config.ts because it identifies the Cloud project. The CYPRESS_RECORD_KEY is the secret that authorizes recording and must stay in your CI secret manager.
Why are my parallel Cypress jobs creating separate Cloud runs?
The workers probably do not share the same CI build identity, commit metadata, project, group, browser, or spec set. Compare the run details and provide a shared --ci-build-id when your CI provider is not detected automatically.
Can Cypress Cloud parallelize tests inside one spec file?
No. Cypress Cloud parallelization schedules whole spec files, not individual tests. Split a dominant spec into independent behavior-focused files if it limits the run after other machines finish.
How can I verify Cypress Cloud load balancing is working?
Open a recorded parallel run and inspect its Machines, Timeline, and spec duration views. Each spec should run once, workers should request work from the same group, and mature suites should show machines staying occupied until near the end.
Related Guides
- Appium Android setup: A Practical Guide (2026)
- Appium iOS setup: A Practical Guide (2026)
- Create Cypress Query Commands with TypeScript: Cypress Query Commands TypeScript Tutorial
- Cypress Modern Test Architecture Complete Guide (2026)
- How to Use Cypress parallelization (2026)
- Selenium Grid Cloud Scaling Complete Guide (2026)