# CI/CD pipeline stages explained, from push to production

> A CI/CD pipeline is an ordered set of automated stages (trigger, checkout, install, test, build, publish, deploy, verify) that turns a commit into running software and stops at the first failure.

URL: https://levelrail.com/learn/ci-cd/ci-cd-pipeline-stages-explained/
Updated: 2026-11-27

A CI/CD pipeline is a fixed series of automated steps that runs on every change: get the code, check it, build it, publish the result, deploy it and confirm it works. Each stage answers one question, and the pipeline stops at the first stage that fails. This lesson goes through the stages in order so you can read any pipeline file and know what each part is for. The intro is in [What is CI/CD](https://levelrail.com/learn/deploy-operate/what-is-ci-cd/)), and the glossary entry for [CI/CD](https://levelrail.com/learn/glossary/#ci-cd)) has the short version.

## How it works

A pipeline is a chain. Each stage starts only when the one before it succeeded, and each produces either a pass or a fail plus logs. The stages fall into two halves. Continuous integration (CI) covers everything up to a tested build artifact. Continuous delivery or deployment (CD) covers moving that artifact to servers.

The stages, in the order most pipelines run them:

1. **Trigger.** Something starts the run: a push, a pull request, a tag, a schedule or a manual button. The trigger decides which commit gets checked.
2. **Checkout.** The runner, a short-lived machine, downloads the commit. It starts empty, so nothing from earlier runs is there unless you cache it.
3. **Install.** Dependencies are restored from a lockfile (`npm ci`, `pip install -r`, `go mod download`). A lockfile makes the install repeatable.
4. **Lint and test.** Static checks and tests. This is the main quality gate and the reason CI exists.
5. **Build.** Compile code or build a [Docker image](https://levelrail.com/learn/glossary/#image)). This is where the artifact is made.
6. **Publish artifact.** Push the image to a [registry](https://levelrail.com/learn/glossary/#registry)) or upload a package, tagged so you can find it later.
7. **Deploy.** Tell the server to run the new artifact.
8. **Verify.** Request a health endpoint or run a smoke test against the live service.

Not every project needs every stage as its own job. A static site might have install, build and deploy. A service with a database might add a migration step before deploy. The order matters more than the count.

## Fast feedback

The point of CI is that a developer learns about a problem while the change is still fresh. Two habits keep feedback fast.

First, order stages by cost. Lint runs in seconds, unit tests in a minute or so, integration tests longer. Run the cheap ones first so most failures show up early.

Second, run independent work in parallel. Lint and unit tests do not depend on each other, so they can be separate jobs that start together. Jobs that need output from another job wait for it. [GitHub Actions workflow anatomy](https://levelrail.com/learn/ci-cd/github-actions-workflow-anatomy/)) shows how that is expressed.

A slow or flaky pipeline gets ignored, and people start merging without waiting. Treat a pipeline that takes too long as a bug in the pipeline.

## Continuous delivery vs continuous deployment

The two terms share the abbreviation CD and differ in one decision.

- **Continuous delivery:** every change that passes the checks produces a release candidate that could go to production. A person presses the button, or approves a pending deploy. Many teams choose this because they want a human to pick the moment.
- **Continuous deployment:** there is no button. A passing change on the main branch goes to production automatically.

Both require the same discipline: main is always releasable, tests are trusted, and you can undo a bad release quickly. Start with delivery and an approval gate. Move to full deployment when you trust your checks and your [rollback](https://levelrail.com/learn/deploy-operate/rollbacks/)) path.

## Build once, deploy many

Build the artifact a single time, early, and promote that same artifact through the later stages. If you rebuild for staging and again for production, the two builds can differ: a dependency resolves differently, a base image moved, an environment variable was baked in. Then your tests ran against something you did not ship.

For containers this is natural. The build stage pushes an image with an immutable tag, such as the commit SHA. Staging and production both pull that tag. Configuration that differs per environment, like database URLs, comes from [environment variables and secrets](https://levelrail.com/learn/deploy-operate/environment-variables-and-secrets/)) at run time, not from the build. Publishing is covered in [Build and push a Docker image to GHCR](https://levelrail.com/learn/ci-cd/build-and-push-docker-image-to-ghcr/)).

## Gates between stages

A gate is a rule that must be true before the pipeline moves on. Tests passing is the basic gate. Others you can add:

- a required review on the pull request before merge
- a manual approval before the production deploy
- a health check that must pass after deploy
- a branch rule so only main can deploy

Gates are how a pipeline turns "we usually test" into "we always test". Branch rules are covered in [Matrix builds and branch protection](https://levelrail.com/learn/ci-cd/matrix-builds-and-branch-protection/)).

## Check it worked

You understand the pipeline when you can trace one commit through it. Open a recent run in your CI tool and answer four questions: what triggered it, which stage took longest, what artifact it produced and where that artifact lives, and how you would find out the deploy actually worked. If you cannot answer the last one, add a verify stage.

## Edge cases and gotchas

- **Deploy success is not app success.** A deploy step that copies files or restarts a container can succeed while the app crashes on boot. Always verify with a request.
- **Rebuilding per environment.** Building again for production breaks the tested-equals-shipped guarantee. Promote the same artifact.
- **Floating tags.** Deploying `latest` means you cannot say which commit is running. Use the commit SHA or a version tag.
- **Tests that need secrets.** Pull requests from forks usually do not receive secrets. Design tests so they pass without them. See [Secrets and variables in CI pipelines](https://levelrail.com/learn/ci-cd/secrets-and-variables-in-ci-pipelines/)).
- **A pipeline nobody trusts.** Flaky tests teach people to click re-run. Fix or delete a flaky test rather than retrying it forever.
- **Database changes ride along.** Migrations are part of the release. If they are not backward compatible, a rollback of the code will not save you.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| Pipeline never starts | The trigger does not match the branch or event | Check the trigger rules against the branch you pushed |
| Passes locally, fails in CI | Different Node or tool version, missing env var | Pin the version in the pipeline and print it in the log |
| Install step is slow every run | No dependency cache | Add a cache, see the caching lesson |
| Deploy step green, site down | No verify stage | Add a health check that fails the job |
| Staging works, production breaks | Artifact rebuilt per environment | Build once and promote the same tag |
| Runs queue up and waste minutes | Many pushes, old runs not cancelled | Add a concurrency group to cancel superseded runs |
| Cannot tell which commit is live | Deploying a floating tag | Tag images with the commit SHA |

## Quick reference

```text
trigger -> checkout -> install -> lint + test -> build
        -> publish artifact -> deploy -> verify

delivery:   human approves the production deploy
deployment: passing changes go live automatically
rule:       build once, promote the same artifact
rule:       cheap checks first, independent jobs in parallel
```

## Related lessons

- [What is CI/CD](https://levelrail.com/learn/deploy-operate/what-is-ci-cd/)): the plain-language introduction to the idea.
- [GitHub Actions workflow anatomy](https://levelrail.com/learn/ci-cd/github-actions-workflow-anatomy/)): how these stages become a workflow file.
- [Run tests on every push and pull request](https://levelrail.com/learn/ci-cd/run-tests-on-every-push-and-pull-request/)): the lint and test stage in practice.
- [Git workflow that triggers a deploy](https://levelrail.com/learn/git/git-workflow-that-triggers-a-deploy/)): how branches and pushes start a pipeline.
- [Rollbacks](https://levelrail.com/learn/deploy-operate/rollbacks/)): what to do when verify fails.

## Next

Continue with [GitHub Actions workflow anatomy](https://levelrail.com/learn/ci-cd/github-actions-workflow-anatomy/)).

## Frequently asked questions

### What are the stages of a CI/CD pipeline?

A typical pipeline has a trigger, a checkout of the code, dependency install, lint and test, a build, publishing the build output, a deploy, and a verification step. Small projects often merge several of these into one job.

### What is the difference between continuous delivery and continuous deployment?

Continuous delivery keeps every change in a releasable state and waits for a person to approve the production deploy. Continuous deployment removes that approval, so every change that passes the checks goes live automatically.

### What does build once, deploy many mean?

You build the artifact (for example a Docker image) one time, then promote that exact artifact through staging and production. You do not rebuild per environment, so what you tested is what you ship.

### Why should a pipeline fail fast?

The sooner a broken commit is rejected, the less time you spend waiting and the cheaper the fix is. Put quick checks such as lint before slow ones such as integration tests.


## Sources

- [GitHub Docs, understanding GitHub Actions](https://docs.github.com/en/actions/get-started/understand-github-actions)
