DEV Community

Parveen Antal
Parveen Antal

Posted on Edited on

I Teach GitLab CI/CD: 5 Pipeline Patterns Every Beginner Should Build First

TL;DR: If you are new to GitLab CI/CD, build these five pipeline patterns in order. They teach you almost everything you need for real projects.

1. The "hello pipeline"

Start with the smallest possible pipeline.

stages:
  - build

build-job:
  stage: build
  script:
    - echo "Building"
Enter fullscreen mode Exit fullscreen mode

Why it matters: it proves your project, runner and YAML all work.

2. Multi-stage pipeline

stages:
  - build
  - test
  - deploy

build-job:
  stage: build
  script:
    - echo "Compiling..."

test-job:
  stage: test
  script:
    - echo "Running tests..."

deploy-job:
  stage: deploy
  script:
    - echo "Deploying..."
Enter fullscreen mode Exit fullscreen mode

Stages run in order. Jobs in the same stage run in parallel.

3. Passing files with artifacts

build-job:
  stage: build
  script:
    - echo "build output" > build.txt
  artifacts:
    paths:
      - build.txt
    expire_in: 1 hour
Enter fullscreen mode Exit fullscreen mode

Later jobs can now use build.txt.

4. Controlling jobs with rules

deploy-job:
  stage: deploy
  script:
    - echo "Deploying to production"
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
Enter fullscreen mode Exit fullscreen mode

This deploys only from the main branch.

5. Running jobs in Docker

test-job:
  stage: test
  image: node:20
  script:
    - node --version
Enter fullscreen mode Exit fullscreen mode

Docker keeps your environment the same every time.

What should you learn next?

After these five, try CI/CD variables for secrets, caching, the GitLab Container Registry, reusable templates with include, and deploying with Terraform or Kubernetes.

I turned this learning path into a hands-on course with 50 practical tasks, from beginner to advanced: https://www.udemy.com/course/gitlab-ci-cd-hands-on-build-your-own-50-gitlab-pipelines/

What was the first pipeline error that confused you? Tell me in the comments.

Top comments (0)