The Stages of a CI/CD Pipeline, Explained

ci/cd pipeline stages

Not sure what happens between your commit and a release? The ci/cd pipeline stages are source, build, test and deploy, and many teams add staging. You’ll see what each does and where failures get caught.

If the terms are new, read what is ci/cd first for the wider picture.

Item Value
Stages in a basic pipeline Source, build, test, deploy
Main phases in a continuous delivery pipeline 5 (build/develop, commit, test, stage, deploy)
Ideal commit stage duration Under 5 minutes
Upper limit for the commit stage No more than 10 minutes
Common deployment methods Blue-green, canary, rolling

These figures come from TechTarget and Codefresh. Vendors name and count stages differently and guidance can change, so check the source before you rely on them.

What the stages of a pipeline are for

GitLab describes a CI/CD pipeline as an automated workflow that guides software from source code through building, testing and releasing stages, as set out on its pipeline explainer. Each stage is a group of related tasks, so a pipeline is a chain of small, checkable steps rather than one big script.

Stages work as gates. According to phoenixNAP, a change moves forward only after it passes the current stage, so problems are caught as early as possible.

When a gate fails, you hear about it. GitLab notes that failure at any stage triggers a notification to alert the engineer responsible.

Counting differs between guides. TechTarget lists a short, four-stage flow, while Codefresh describes a delivery pipeline with five phases. The underlying flow is the same: take a change, prove it works, and move it towards users.

Source and commit: where every run begins

The source stage takes a change to an app’s code, configuration, environment or data and triggers a new instance of the pipeline, per TechTarget. The version control system can start a run on events such as a branch push or pull request validation.

Next, the pipeline fetches the latest code and its dependencies. Codefresh says modern pipelines often prepare an isolated container environment that holds the required code and tools and can be discarded and recreated reliably.

The commit stage then runs quick checks. The same Codefresh guide lists these early checks:

  • Linting, to catch syntax errors and enforce coding standards.
  • Static code analysis.
  • Security scans, to identify vulnerabilities early on.

Some pipelines also add peer code review at this point, as an extra layer of scrutiny before code merges into the main branch. Our guide on how to automate code review covers how to take some of that load off your reviewers.

Speed matters here. Codefresh’s delivery-pipeline guide says the commit stage should ideally finish in less than five minutes and no longer than ten, which keeps feedback close to the moment you wrote the code. You can read that on its five-stage page.

Build and artifact stages

In the build stage, the code is compiled into an artifact, such as a binary, package or container, with fast-running tests to detect problems with the new version, according to the Codefresh process guide. A failed build triggers alerts so the team can fix it quickly.

Which engine runs the build is your call. TechTarget names self-hosted Jenkins and third-party alternatives such as GitHub Actions, CircleCI and Azure Pipelines. If you want to write a pipeline yourself, the github actions tutorial is a practical next step.

Pipeline definitions belong in the repository. phoenixNAP explains that because the file lives alongside the code, reviewers check pipeline changes like any other code.

Once a build succeeds, the artifact repository stage stores the result. Codefresh says this artifact serves as the definitive version of the software, so the artifact that was validated is the same one deployed to end users.

Test stage: the safety net

The test stage checks that changes do not break logic or functionality. TechTarget describes three common layers:

  1. Unit tests, which examine small units of application code in isolation.
  2. Integration tests, which analyze individual units of code together in a group.
  3. End-to-end functional tests, which put the software in an environment that mimics a production deployment.

Order matters. phoenixNAP says automated tests run from fastest to slowest, so cheap checks fail first and slow ones only run on builds that deserve them. Codefresh adds regression testing, which helps ensure new additions do not break previously working features.

Fast answers are the goal. A developer should know within five minutes whether the build and test stage has a problem, according to Codefresh, so they can fix it while the change is fresh in their mind.

You can also make coverage a gate. TechTarget suggests keeping a predetermined code coverage benchmark and failing the stage if coverage drops below the threshold.

ci/cd pipeline stages Diagram sketching
A person holds a marker against a white surface with connecting lines and shapes.

Staging and deploy: delivery or deployment?

The staging environment is a replica of production. Codefresh says it mimics the real setting, including hardware, software, configuration, architecture and scale, and it is the last phase before changes reach the live environment.

The deploy stage is where the two meanings of CD split. phoenixNAP puts it plainly: continuous delivery requires a person to approve each production release, while continuous deployment removes that approval step and lets any change that passes automated checks go live.

That second route carries risk. GitLab warns there is no manual barrier before production, so watertight test automation is essential. phoenixNAP adds that teams using it also add safeguards such as automatic rollback and feature flags.

Whichever route you take, you still choose how a release reaches users. TechTarget lists these common methods:

  • Blue-green deployments.
  • Canary deployments.
  • Rolling deployments.

How do you choose which stages to include?

There is no single correct pipeline. TechTarget notes that every organization sets up a CI/CD pipeline differently, based on its internal processes, resources and infrastructure.

A sensible approach is to build up in layers:

  1. Start with source, build and test, so every commit gets automatic feedback.
  2. Add an artifact store and a staging environment, so what you test is what you ship.
  3. Decide on approval. Keep a human gate until your tests earn trust.

On that last point, phoenixNAP calls continuous deployment an optional extension for projects with enough test coverage for changes to be released without manual approval. Treat it as a goal, not a starting point.

Frequently asked questions

Is a CI/CD pipeline the same as continuous integration?

Show answer

No. According to phoenixNAP, continuous integration covers merging and testing code, while continuous delivery covers preparing tested code for release. The pipeline is the ordered sequence of stages that carries both. See the phoenixNAP guide.

How many stages does a pipeline have?

Show answer

It depends on who is counting. TechTarget lists source, build, test and deploy, while Codefresh’s continuous delivery guide names five phases: build/develop, commit, test, stage and deploy.

What happens when a stage fails?

Show answer

phoenixNAP says the server stops the pipeline and alerts the developer who made the change through chat, email or the merge request itself. The failed change goes no further until it is fixed.

Do I need a staging environment?

Show answer

TechTarget says that ideally there are multiple environments through which built artifacts are released and tested before production. Staging is the usual last one before going live.