DevOps · CI/CD

Build Pipelines

The build pipeline turns source code into a tested, versioned artifact ready to deploy.

Intermediate 5 min Lesson 10 of 30
0/30 in DevOps
On this page · 5 min · Intermediate

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#

YAML.github/workflows/build.yml Illustrative
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 }}
Expected output
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#

  1. npm ci installs exactly what the lock file says.
  2. Lint and tests run before packaging.
  3. The built-in GITHUB_TOKEN logs in to GitHub Container Registry.
  4. 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#

npm install in CI

It may update the lock file. Use npm ci for reproducible installs.

Only “latest” tags

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
Shell Illustrative
dotnet restore --locked-mode

Mini quiz#

Build Pipelines quizMultiple choice Question 1 of 1

Why tag images with the commit SHA?

Score so far: 0/0

Want more? Practise all DevOps MCQs · DevOps interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.