Skip to content
Tutorials Center
My learning

Topics

Lesson 44 of 44 ยท Practice and Review

CI/CD Cheat Sheet

A side-by-side CI/CD cheat sheet for GitHub Actions, Jenkins and GitLab: triggers, jobs, expressions, caching, secrets, artifacts and common recipes.

This page is a quick reference for the whole track. It puts the three tools side by side so you can move between them, and it collects the snippets you reach for most: triggers, conditions, caching, secrets, artifacts and deployment gates. It does not teach anything new; each section links to the lesson that explains the idea.

All configuration here is read-only, because the real tools need a server or an account. Two small stand-in demos at the end are plain JavaScript models: a concept translator and a cron-field reader. They show the shape of the ideas, not the behavior of the real products. Keep claims about version numbers loose: pin the versions you use and check the current documentation when a detail matters.

Concept map

Idea GitHub Actions Jenkins GitLab CI/CD
Config file .github/workflows/*.yml Jenkinsfile (Groovy) .gitlab-ci.yml
Pipeline unit workflow pipeline pipeline
Group of work job stage stage (contains jobs)
Unit that runs step step script line in a job
Worker runner agent / node runner (with an executor)
Pick a worker runs-on agent { label '...' } tags
Trigger on: SCM webhook, triggers {} pushes, MRs, rules, schedules
Order needs stage order, parallel stages, needs
Condition if: when {} rules:
Secrets secrets.NAME credentials store masked CI/CD variables
Reuse reusable workflow, composite action shared library include, extends
Outputs kept upload-artifact archiveArtifacts artifacts:
flowchart LR
  T["Trigger<br/>push or pull request"] --> B["Build"]
  B --> Q["Test and checks"]
  Q --> A["Artifact"]
  A --> S["Deploy to staging"]
  S --> G{"Approval"}
  G --> P["Deploy to production"]

The same flow in every tool: only the keywords change.

Minimal pipelines

GitHub Actions:

YAML
name: CI
on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test

Jenkins (declarative):

GROOVY
pipeline {
  agent any
  stages {
    stage('Install') { steps { sh 'npm ci' } }
    stage('Test')    { steps { sh 'npm test' } }
  }
  post {
    always  { junit allowEmptyResults: true, testResults: 'reports/*.xml' }
    failure { echo 'Build failed' }
  }
}

GitLab CI/CD:

YAML
stages: [test]

test:
  stage: test
  image: node:22
  script:
    - npm ci
    - npm test

See Your First Workflow, The Declarative Jenkinsfile and GitLab CI/CD Basics.

Triggers and conditions

Need GitHub Actions GitLab CI/CD Jenkins
Only on main on: push: branches: [main] rules: - if: $CI_COMMIT_BRANCH == "main" when { branch 'main' }
Pull / merge requests on: pull_request if: $CI_PIPELINE_SOURCE == "merge_request_event" multibranch pull request discovery
Only if files changed paths: filter rules: - changes: [src/**/*] when { changeset 'src/**' }
Manual run workflow_dispatch when: manual input step or parameters
Schedule schedule: - cron: '0 3 * * 1' pipeline schedule in the UI triggers { cron('H 3 * * 1') }
Tag releases push: tags: ['v*'] if: $CI_COMMIT_TAG when { tag 'v*' }

Cron has five fields: minute, hour, day of month, month, day of week. GitHub Actions evaluates schedules in UTC. Jenkins accepts H to spread load. Details: Triggers: push, pull_request, schedule and More.

GitHub Actions expressions

YAML
if: github.ref == 'refs/heads/main'
if: github.event_name == 'pull_request'
if: startsWith(github.ref, 'refs/tags/v')
if: contains(github.event.head_commit.message, '[skip deploy]')
if: ${{ !cancelled() }}
if: always()
if: failure()
run: echo "${{ format('{0}-{1}', runner.os, github.sha) }}"
Context Typical content
github event, ref, sha, actor, repository
env environment variables set in the workflow
vars / secrets repository, organization or environment values
matrix the current matrix combination
needs results and outputs of earlier jobs
steps outputs and outcome of earlier steps in the job
runner os, arch, temp directory

Handy functions: contains, startsWith, endsWith, format, join, toJSON, fromJSON, hashFiles. Status functions: success(), failure(), always(), cancelled(). More in Expressions and Contexts.

Outputs between steps and jobs:

YAML
jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.ver.outputs.version }}
    steps:
      - id: ver
        run: echo "version=1.4.0" >> "$GITHUB_OUTPUT"
  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploying ${{ needs.build.outputs.version }}"

Matrix, concurrency and timeouts

YAML
strategy:
  fail-fast: false
  max-parallel: 4
  matrix:
    os: [ubuntu-latest, windows-latest]
    node: [20, 22]
    exclude:
      - os: windows-latest
        node: 20
    include:
      - os: ubuntu-latest
        node: 24
        experimental: true
timeout-minutes: 15
YAML
concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

Use cancel-in-progress: true for pull request checks, and leave it off for deployments. See Matrix Builds.

Caching

GitHub Actions:

YAML
- uses: actions/cache@v4
  with:
    path: ~/.npm
    key: npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      npm-${{ runner.os }}-

GitLab CI/CD:

YAML
cache:
  key:
    files: [package-lock.json]
  paths:
    - .npm/

Jenkins has no built-in dependency cache: use a persistent agent workspace, a Docker volume or a plugin. A key built from the lock file changes exactly when dependencies change; a restore key gives a partial match as a fallback. Many setup-* actions have a cache: option that does this for you. Details: Caching and Artifacts.

Artifacts

Tool Save Use later
GitHub Actions actions/upload-artifact@v4 with name and path actions/download-artifact@v4 in a later job
Jenkins archiveArtifacts artifacts: 'dist/**' stash / unstash inside one run
GitLab CI/CD artifacts: paths: [dist/] and expire_in later stages download them automatically; narrow with needs or dependencies

A cache is allowed to be missing; an artifact is a result you depend on.

Secrets and permissions

GitHub Actions:

YAML
permissions:
  contents: read
steps:
  - run: ./publish.sh
    env:
      NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Jenkins:

GROOVY
withCredentials([string(credentialsId: 'npm-token', variable: 'NPM_TOKEN')]) {
  sh './publish.sh'
}

GitLab CI/CD: define a variable in the project settings with the masked (and, for protected branches, protected) options, then read $NPM_TOKEN in the script.

Rules to remember: pass secrets through environment variables, never print them, rotate anything that leaks, prefer short-lived OIDC credentials, and give the token the fewest permissions. Details: Secrets, Variables and Environment Variables and Securing Your Pipeline.

Security checklist

  • Pin third-party actions to a full commit SHA and let a bot propose updates.
  • Never put untrusted text (titles, branch names, commit messages) inside a run script through ${{ }}; pass it with env:.
  • Avoid running pull request code in pull_request_target.
  • Scope secrets to environments and require approval for production.
  • Turn on secret scanning and dependency review; produce an SBOM and sign releases where it matters.

Services, containers and deployment gates

YAML
# GitHub Actions: a database for tests
services:
  db:
    image: postgres:17
    env:
      POSTGRES_PASSWORD: example
    ports: ["5432:5432"]
    options: >-
      --health-cmd "pg_isready -U postgres"
      --health-interval 5s
      --health-retries 10
YAML
# GitLab CI/CD: environment with a manual production deploy
deploy_production:
  stage: deploy
  script: ./deploy.sh production
  environment: production
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
      when: manual
YAML
# GitHub Actions: environment with required reviewers
deploy:
  runs-on: ubuntu-latest
  environment: production
  concurrency: deploy-production

Required reviewers are configured in the environment's settings, not in the YAML. See Environments, Approvals and Deployments and Deployment Strategies.

Debugging commands

Goal Try
Reproduce a GitHub workflow locally act (runs most workflows in Docker; not identical to GitHub)
Reproduce a GitLab job locally run the job's image and script by hand in Docker
Verbose GitHub logs re-run the job with debug logging enabled
Validate YAML the editor's linter, or the platform's lint tool for .gitlab-ci.yml
Check what ran read the first failing step, not the last error

More in Debugging Failing Pipelines.

Release and speed recipes

  • Semantic versions: MAJOR.MINOR.PATCH. A breaking change bumps major, a feature bumps minor, a fix bumps patch. Conventional commit prefixes feat:, fix: and feat!: map to those bumps. See Versioning and Automated Releases.
  • Tag images with the commit SHA, plus a moving tag such as latest or a version, and deploy by SHA. See Building and Pushing Docker Images.
  • Faster pipelines: cache dependencies, run independent jobs in parallel, filter by path, use shallow clones and trim the critical path. See Making Pipelines Fast.
  • DORA metrics: deployment frequency, lead time for changes, change failure rate and time to restore service. See Pipeline Metrics and Maintenance.

Stand-in: a concept translator

This model stores the concept map as data and answers "what is X called in tool Y?". It is a plain lookup, not a conversion of real configuration.

JS Concept translator

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The last line shows the limit of any cheat sheet: a missing row means you must read the documentation.

Stand-in: reading a cron expression

Schedules trip people up. This model labels the five fields of a cron expression and handles only simple values (*, a number, a list or */n). Real cron supports more syntax.

JS Label the five cron fields

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The expression 0 3 * * 1 means 03:00 every Monday (in UTC on GitHub), and the broken last one is caught because it has four fields.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which GitLab keyword plays the role of the GitHub Actions if: condition for a job?

    rules decide whether a job is added to a pipeline and how, based on variables, changed files and more.
  2. 2. What is a good cache key for npm dependencies?

    A key that includes the lock file hash changes exactly when the dependencies change, so the cache is reused otherwise.
  3. 3. When should cancel-in-progress be left off?

    Cancelling a deployment halfway can leave a system in a mixed state. Cancel outdated checks, not running deploys.
  4. 4. In Jenkins, how do you expose a credential to a block of steps without hard-coding it?

    withCredentials binds a stored credential to a variable only inside the block and masks it in the console log.

Summary

  • The three tools share the same ideas under different names: workflow or pipeline, job or stage, runner or agent, if or when or rules.
  • Triggers, conditions, matrices, caches and artifacts have a close equivalent in each tool; Jenkins relies more on plugins and agent setup.
  • Secrets go through environment variables or credential bindings, never into logs, with the smallest permissions that work.
  • Deployments need gates (approvals, concurrency, smoke checks) and a quick way back.
  • When a detail is uncertain, check the current documentation and pin the versions you depend on.

This is the last lesson of the track. To revisit the details, start again from What Is CI/CD?.