CI/CD Pipelines: Foundations and Examples

Core CI/CD concepts plus starter examples for GitHub Actions, GitLab CI, and Jenkins.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Pipeline building blocks

Understand the stages and core files behind CI/CD.

Minimal GitHub Actions pipeline

Build and test on pushes and pull requests.

yamlANYgithub-actionsbasicnode
yaml
name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - run: npm ci
      - run: npm test
      - run: npm run build
Notes

Use this as a compact baseline for CI: checkout, install, test, and build.

Minimal GitLab CI pipeline

Run install, test, and build using stages.

yamlANYgitlabbasicnode
yaml
stages:
  - test
  - build

default:
  image: node:20

cache:
  paths:
    - node_modules/

test:
  stage: test
  script:
    - npm ci
    - npm test

build:
  stage: build
  script:
    - npm ci
    - npm run build
Notes

GitLab pipelines are defined in `.gitlab-ci.yml` and usually organized with `stages` and jobs.

Minimal Jenkins declarative pipeline

Run checkout, install, test, and build in a Jenkinsfile.

groovyANYjenkinsbasicdeclarative
groovy
pipeline {
  agent any

  stages {
    stage('Checkout') {
      steps { checkout scm }
    }
    stage('Install') {
      steps { sh 'npm ci' }
    }
    stage('Test') {
      steps { sh 'npm test' }
    }
    stage('Build') {
      steps { sh 'npm run build' }
    }
  }
}
Notes

Jenkins supports declarative and scripted pipeline syntax. Declarative is easier to read and standardize.

Branching and trigger patterns

Choose when CI runs and what it validates.

Validate pull requests only

Run CI before code reaches main.

yamlANYpull-requestvalidation
yaml
on:
  pull_request:
    branches: [main]
Notes

PR validation is the safest default for lint, unit tests, type checks, and build verification.

Deploy only from main

Restrict production deployment to your protected main branch.

yamlANYdeploymain-branch
yaml
on:
  push:
    branches: [main]
Notes

Keep deploy workflows tighter than CI workflows. A common split is PR checks for CI and push-to-main for CD.

Nightly scheduled workflow

Run audits, backups, smoke tests, or dependency checks on a schedule.

yamlANYschedulecron
yaml
on:
  schedule:
    - cron: "0 6 * * *"
Notes

Schedules are ideal for recurring maintenance and longer-running jobs that do not need to run on every commit.

Recommended next

No recommendations yet.