惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
宝玉的分享
宝玉的分享
月光博客
月光博客
B
Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
博客园_首页
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
A
About on SuperTechFans
Y
Y Combinator Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
D
Docker
爱范儿
爱范儿
博客园 - 司徒正美
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
CI/CD Pipelines That Actually Work: From “Why Is This Bro...
Timevolt · 2026-06-20 · via DEV Community

The Quest Begins (The "Why")

Picture this: I’m hunched over my laptop at 2 a.m., coffee cold, staring at a red GitHub Actions badge that stubbornly reads “failed”. I’d just pushed a tiny UI tweak, and the pipeline decided it was the perfect moment to remind me that my node_modules cache was older than the dinosaurs in Jurassic Park. I’d spent the last hour wrestling with a flaky test that only failed on Windows runners, and the CI log was a wall of text that looked like the scrolls in The Lord of the Rings – epic, but completely indecipherable.

Honestly, I felt like a rookie Jedi trying to lift an X‑wing with the Force while everyone else was already flying Millennium Falcons. The pain point? Reliability. My team kept shipping hotfixes because the pipeline would randomly drop artifacts, skip steps, or hang forever on a dependency install. I needed a pipeline that didn’t feel like a boss battle every time I hit merge. So I embarked on a quest: find the holy grail of CI/CD that just works across GitHub Actions, GitLab CI, and Jenkins – the three kingdoms I most often serve.

The Revelation (The Insight)

After a weekend of digging through docs, trial‑and‑error, and a few “why did I even try this?” moments, the breakthrough came when I stopped treating each CI system as a black box and started thinking about pipeline as code – the same way we treat application code. The magic? Declarative, version‑controlled, and reusable steps that are isolated, cache‑smart, and fail fast.

Think of it like Neo seeing the Matrix: once you realize the pipeline is just another piece of software, you can refactor, test, and version it just like your src folder. The three pillars that made the difference for me:

  1. Explicit caching – store only what really changes (lockfiles, build artifacts).
  2. Matrix builds with fail‑fast – test multiple environments but bail out on the first failure to save time.
  3. Self‑contained jobs – each job pulls its own dependencies, uses containers where possible, and leaves no dirty state behind.

When I applied these ideas, the red badge turned green, and the pipeline ran in under 5 minutes instead of the dreaded 20‑minute slog. I felt like I’d just discovered the secret level in Super Mario Bros. – a warp pipe straight to the flagpole.

Wielding the Power (Code & Examples)

Below are the “before” (the struggle) and “after” (the victory) snippets for each platform. I’ll point out the traps I fell into so you can dodge them like a pro.

GitHub Actions – The Cache That Actually Caches

Before – naive caching that stored the whole node_modules folder, causing huge restores and occasional corruption.

# .github/workflows/ci.yml (before)
name: CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Cache node_modules
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      - run: npm ci
      - run: npm test

The trap: caching ~/.npm works, but if you lock the key only to package-lock.json and change a dependency version, you get a miss and end up reinstalling everything from scratch – still slow, but at least correct. The real win came when I split the cache into two layers: one for the lockfile (restore) and another for the actual node_modules (save).

After – split‑cache strategy + matrix with fail‑fast.

# .github/workflows/ci.yml (after)
name: CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x]
      fail-fast: true   # <-- stop as soon as one version fails
    steps:
      - uses: actions/checkout@v3

      - name: Cache npm packages (lockfile)
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Cache node_modules (actual)
        uses: actions/cache@v3
        with:
          path: ~/.npm/_cachelog
          key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-modules-

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - run: npm ci
      - run: npm test

Why it works: The first cache restores the download folder (fast), the second caches the already‑installed modules (even faster). The matrix runs two Node versions in parallel, and fail-fast means we don’t waste time if the first version blows up.

GitLab CI – Docker‑in‑Docker Done Right

Before – trying to build Docker images inside a shell executor, leading to permission errors and flaky layer caches.

# .gitlab-ci.yml (before)
stages:
  - build
  - test

build_image:
  stage: build
  script:
    - docker build -t myapp:$CI_COMMIT_SHA .
    - docker push myapp:$CI_COMMIT_SHA

run_tests:
  stage: test
  script:
    - docker run --rm myapp:$CI_COMMIT_SHA npm test

The trap: GitLab’s shared runners often run with a restrictive AppArmor profile; Docker‑in‑DinD needs privileged mode, and without it you get “operation not permitted”. Plus, each job started from scratch, pulling base images every time.

After – use the Docker executor with privileged mode and cache layers via :cache-from.

# .gitlab-ci.yml (after)
stages:
  - build
  - test

variables:
  DOCKER_DRIVER: overlay2   # faster storage driver
  IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

build:
  stage: build
  image: docker:latest
  services:
    - docker:dind   # Docker-in-Docker service
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  before_script:
    - docker info
  script:
    - docker build --cache-from $IMAGE -t $IMAGE .
    - docker push $IMAGE

test:
  stage: test
  image: docker:latest
  services:
    - docker:dind
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  script:
    - docker pull $IMAGE
    - docker run --rm $IMAGE npm test

Why it works: By declaring docker:dind as a service, GitLab gives us a privileged Docker daemon inside the job. The --cache-from flag tells Docker to reuse previously pushed layers, turning a 2‑minute build into a 20‑second incremental one. No more “permission denied” surprises.

Jenkins – Declarative Pipeline with Shared Libraries

Before – a sprawling Scripted Pipeline copied across repos, hard‑coded paths, and no way to reuse common steps (like setting up Maven or caching Gradle).

// Jenkinsfile (before)
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'mvn clean install -DskipTests'
            }
        }
        stage('Test') {
            steps {
                sh 'mvn test'
            }
        }
    }
}

The trap: Adding a new stage meant editing every Jenkinsfile. If the Maven version changed, you hunted down each file. Also, the agent any could land on a node missing JDK 11, causing cryptic “class not found” errors.

After – a Declarative Pipeline that pulls a shared library for common tooling and uses an agent label to guarantee the right environment.

// vars/commonTools.groovy (in shared library)
def call(Map config = [:]) {
    def toolName = config.toolName ?: 'maven'
    def version  = config.version ?: '3.9.0'
    def toolHome = tool name: toolName, version: version
    withEnv(["PATH+${toolHome}/bin=${toolHome}/bin"]) {
        return
    }
}

// Jenkinsfile (after)
@Library('my-org-pipeline-lib@main') _

pipeline {
    agent {
        label 'java11-node'   // ensures we have JDK 11 + Node if needed
    }
    options {
        timeout(time: 30, unit: 'MINUTES')
        timestamps()
    }
    stages {
        stage('Prepare') {
            steps {
                script {
                    commonTools toolName: 'maven', version: '3.9.0'
                    commonTools toolName: 'nodejs', version: '20.x'
                }
            }
        }
        stage('Build') {
            steps {
                sh 'mvn clean install -DskipTests'
            }
        }
        stage('Test') {
            steps {
                sh 'mvn test'
            }
        }
    }
}

Why it works: The shared library encapsulates the tooling logic; updating the Maven version is a one‑liner in the library, instantly propagating to all repos. The agent label guarantees we never run on a node lacking the required JDK, eliminating those dreaded “unsupported class version” errors. Plus, the Declarative syntax gives us nice stage visualization and built‑in post‑actions (like archiving test results) for free.

Why This New Power Matters

With these patterns in place, my CI/CD pipelines stopped feeling like a chore and started feeling like a force multiplier. I can now:

  • Ship faster – a typical PR builds and tests in under 5 minutes on GitHub Actions, giving reviewers quick feedback.
  • Reduce flakiness – caching and containerized environments mean the same bits run everywhere, from my laptop to the production cluster.
  • Empower the team – anyone can add a new job or tweak a matrix without digging through spaghetti scripts; the pipeline is just another readable piece of code.

In short, I went from dreading the red badge to celebrating the green one every time I push. It’s like finally mastering the lightsaber after months of fumbling with a wooden stick – the moment you feel the power humming in your hand.

Your Turn – Embark on Your Own Quest

Now it’s your turn to take up the mantle. Pick one of the three systems you use most, copy the “after” snippet, and try swapping in your own build commands. Watch the pipeline go from a flaky monster to a reliable sidekick. And when you see that green checkmark, ask yourself:

What’s the next automation dragon I can slay with a declarative pipeline?

Share your wins (or your hilarious fails) in the comments – I love hearing how fellow developers are bending CI/CD to their will. Happy hacking, and may your pipelines ever be green! 🚀