Skip to content
Latchkey

What Is a Build Stage? The Compile-and-Package Phase

A build stage is the pipeline phase that turns source code into runnable artifacts, such as compiled binaries or container images, before testing or deploying.

Most pipelines start with a build stage. This is where source becomes something you can run or ship: compiling code, bundling assets, building a container image. Everything after depends on it, so the build stage usually comes first and its output (the artifact) flows downstream to the test and deploy stages.

What happens in the build stage

  • Install dependencies the build needs.
  • Compile or transpile source code.
  • Bundle assets and package the output.
  • Produce an artifact for later stages.

Why it comes first

You cannot test or deploy what has not been built. The build stage produces the artifact that the test stage exercises and the deploy stage ships. A build failure stops the pipeline before any later stage runs.

A quick example

A Node build stage runs npm ci then npm run build, producing a dist/ folder uploaded as an artifact. The test stage downloads dist/ and runs against it; the deploy stage ships the same artifact.

Building once, using everywhere

A good practice is to build the artifact once and reuse it in every later stage, rather than rebuilding per stage. This guarantees test and production run the exact same bits and saves the cost of repeated builds.

Build stage speed

Builds are often the slowest stage because of dependency installs and compilation. Caching dependencies and build layers is the biggest lever. Managed runners (Latchkey) keep those caches warm so the build stage starts from a primed state instead of a cold one.

Key takeaways

  • A build stage turns source into runnable artifacts before test and deploy.
  • It comes first because later stages depend on its output.
  • Build the artifact once and reuse it downstream for consistency and speed.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →