Course contentsShow
← Cloud and Infrastructure
Lesson 1740 of 2,98936. GitLab CI/CDFree lesson

Basic Pipeline Patterns: Build, Test, Deploy

Implement a simple three-stage pipeline demonstrating the fundamental CI/CD workflow pattern.

Basic Pipeline Patterns: Build, Test, Deploy

You'll learn how to structure a fundamental three-stage CI/CD pipeline that moves code from source to production through build, test, and deploy phases.

The Classic Three-Stage Pattern

Think of a CI/CD pipeline like an assembly line for software. The Build, Test, Deploy pattern is the industry-standard workflow that ensures code quality gates before release. Each stage has a clear purpose:

  • Build: Compile code, bundle assets, create artifacts
  • Test: Validate functionality, catch bugs early
  • Deploy: Push artifacts to target environments

This linear progression mirrors how you'd manually prepare software for release, but automated and repeatable.

Implementing the Pattern in GitLab

Using stages you've learned, structure your .gitlab-ci.yml like this:

stages:
  - build
  - test
  - deploy

build_job:
  stage: build
  script:
    - echo "Compiling application..."
    - mkdir build && echo "app-v1.0" > build/app.bin
  artifacts:
    paths:
      - build/

test_job:
  stage: test
  script:
    - echo "Running tests on build artifacts..."
    - test -f build/app.bin && echo "Tests passed"

deploy_job:
  stage: deploy
  script:
    - echo "Deploying to production..."
    - cp build/app.bin /deploy/location
  environment:
    name: production

Each stage runs sequentially—test won't start until build succeeds, deploy waits for test to pass. Job artifacts carry the build output forward through stages, ensuring you deploy exactly what you tested.

Why This Pattern Works

This pattern creates quality gates: if tests fail, deployment never happens. Your pipeline becomes a safety net, catching issues before they reach users.

Key Takeaway: The Build-Test-Deploy pattern is the foundational CI/CD workflow—each stage acts as a checkpoint, ensuring only validated code reaches production.