Build Pipelines
The build pipeline turns source code into a tested, versioned artifact ready to deploy.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 29, 2026
Related tutorials
Interview questions
Learning objectives#
- Design build stages
- Version every build
- Publish artifacts and images
- Make builds fast and reproducible
Explanation#
Typical steps: checkout → restore dependencies → build → unit test → lint/format check → package (zip or Docker image) → publish artifact.
Reproducible builds use lock files (packages.lock.json, package-lock.json) and pinned tool versions.
Version every artifact: semantic version from a Git tag, or the commit SHA.
Code example: Build and publish a Node.js API image#
name: build
on: { push: { branches: [main] } }
permissions: { contents: read, packages: write }
jobs:
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 22, cache: npm }
- run: npm ci && npm run lint && npm test
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
Each commit to main produces an image such as ghcr.io/asha/shop-api:3f2a9c1… after lint and tests pass.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- npm ci installs exactly what the lock file says.
- Lint and tests run before packaging.
- The built-in GITHUB_TOKEN logs in to GitHub Container Registry.
- The image tag is the commit SHA — unique and traceable.
Real-world use case#
Every commit has a matching image, so you can deploy or roll back to any exact version.
Common mistakes#
It may update the lock file. Use npm ci for reproducible installs.
You cannot tell which code is running. Tag with SHA or version.
Best practices#
- Lock files + pinned tool versions
- Fail fast: lint and tests before packaging
- Tag artifacts with SHA/version
- Cache dependencies and Docker layers
Remember this#
Restore → build → test → package → publish.
npm ci / dotnet restore --locked-mode.
Every artifact has a unique version.
Practice exercise#
Your task: Which command installs .NET dependencies exactly as locked?
Show solution
dotnet restore --locked-mode
Mini quiz#
Why tag images with the commit SHA?
Want more? Practise all DevOps MCQs · DevOps interview questions
My notes#
Saved in this browser.