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
Minimal GitHub Actions pipeline
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

# Build and test on pushes and pull requests.

Minimal GitLab CI pipeline
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

# Run install, test, and build using stages.

Minimal Jenkins declarative pipeline
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' }
    }
  }
}

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

## Branching and trigger patterns
Validate pull requests only
on:
  pull_request:
    branches: [main]

# Run CI before code reaches main.

Deploy only from main
on:
  push:
    branches: [main]

# Restrict production deployment to your protected main branch.

Nightly scheduled workflow
on:
  schedule:
    - cron: "0 6 * * *"

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

Recommended next

No recommendations yet.