CI/CD·8 min read·

Test Environments in CI: Previews vs Full Staging

Choose between ephemeral per-PR previews and a long-lived staging environment for realistic integration testing.

NB

Netbay Engineering

Netbay Engineering

On this page

Once CI produces an artifact, you need somewhere to run it that is not production. Two patterns dominate: ephemeral preview environments spun up per pull request, and a long-lived staging environment you promote into. They are not competitors — they serve different purposes and mature teams use both. This post lays out the trade-offs and a realistic way to combine them.

What Each Pattern Is For

  • **Ephemeral previews** create a short-lived copy of your app for every pull request, give it a unique URL, and tear it down when the PR merges or closes. Perfect for quick manual review and auto-generated test suites that a specific change needs.
  • **Full staging** is a persistent environment that stays running, mirrors production configuration closely, and receives the artifact after previewed changes merge. Best for integration tests that need a realistic stack and shared services.

Previews answer "does this change look and work right?" Staging answers "does this change work alongside everything else?"

Ephemeral Previews In Practice

Ephemeral previews shine for frontend and small-service work where the whole app can launch fast. The pipeline builds the artifact, provisions a temporary environment, deploys it, tests it, then cleans up.

yaml
  preview:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm run build
      - run: |
          scripts/make-preview.sh
          echo "preview ready"
      - name: Report preview URL
        run: |
          echo "preview at https://pr-$PR_NUM.$PREVIEW_DOMAIN"
        env:
          PR_NUM: ${{ github.event.pull_request.number }}
          PREVIEW_DOMAIN: preview.example.com

A few notes on real previews. Tear-down must run reliably on both merge and close, else you leak environments. Naming by PR number keeps URLs predictable. And a preview with an old artifact is worthless — always build the artifact fresh in the PR job, never reuse a cached build.

Full Staging Environments

Staging is where you test the *composition*. It runs the artifact that will go to production, against the same database morphologies and dependent services you will use in production, only with different data and no real traffic.

The key discipline for staging is that it must consume the exact artifact you will deploy to production. Never rebuild staging from source after the build stage — pull the stored artifact and run it. That is what makes staging results meaningful.

yaml
  staging:
    runs-on: ubuntu-latest
    environment: staging
    needs: build
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: web-dist
      - run: |
          scripts/deploy-staging.sh
          echo "staged build ready for integration"
pull request ephemeral preview short-lived URL merge to main artifact full staging long-lived tear down preview cleanup integration tests then production

Sequencing the Two Patterns

A healthy flow uses previews early and staging later:

  1. Every PR gets a preview for quick verification.
  2. Merging produces a fresh artifact.
  3. Staging deploys that artifact and runs integration tests.
  4. Only a green staging run allows promotion to production.

Previews catch a class of issues cheaply and immediately. Staging catches composition and integration issues that no preview could. Each has its lane, and neither substitutes for the other.

When Previews Are Not Enough

Previews break down when the app depends on shared state — a message queue, a common database, third-party webhooks. A preview of just one service without the shared infrastructure gives misleading confidence. When your service is a small piece of a larger system, prefer a scaled-down staging that runs the real dependencies, or a lightweight preview that connects to an isolated shared tier.

Environments and Approval

CI platforms model these as environments with associated rules: previews are often worth mapping to a preview environment so tear-down is tracked, and staging can have its own approval gate separate from production. Configuring environment protection rules keeps the mapping between the runner job and the actual deployment target explicit.

Takeaway

Use ephemeral previews to verify individual changes cheaply and quickly on pull requests; use a long-lived staging environment to verify how the merged artifact composes with everything else. Both consume the same artifact, and only a green staging run earns the right to promote.

Each preview and staging slice needs an isolated VPS, and Netbay lets you create and destroy instances in seconds — manage your environments at netbayhosts.in.

Keep reading

Follow along on a real VPS

Deploy Linux in under 60 seconds

These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.

Deploy an instance