Skip to content

CI/CD Overview

理解 continuous integration and continuous delivery for automated, reliable 发布.

你将学到

  • 什么 CI and CD 平均值 and 如何它们 differ
  • CI/CD 流水线 stages
  • Benefits 的 automated 测试 and 部署
  • Popular CI/CD tools and platforms

概念讲解

What Is CI/CD?

Continuous Integration (CI) is the practice of merging code changes into a shared branch frequently — usually multiple times a day. Each merge triggers an automated build and test suite, catching integration errors within minutes. Continuous Delivery (CD) extends CI by ensuring every change is releasable and can be deployed to production with a single command. Continuous Deployment (also CD) goes one step further and deploys every passing change to production automatically.

The Pipeline Stages

A typical CI/CD pipeline has several stages. Source triggers the pipeline on a push or pull request. Build compiles the code and creates artifacts. Test runs unit, integration, and end-to-end tests. Staging deploys to a pre-production environment for manual verification. Production deploys the verified artifact to live servers. Each stage gates the next — if tests fail, the pipeline stops and the team is notified.

Benefits

CI/CD reduces the risk of releases by making them routine and automated. Instead of a stressful manual deployment every few weeks, you deploy small changes multiple times a day. Automated tests catch bugs before they reach production. Rollbacks are instant because every deployment is versioned. The team gets fast feedback on every change, and the deployment process is consistent and repeatable — no more "它工作 on my machine."

Popular Tools

GitHub Actions is built into GitHub and uses YAML workflows. GitLab CI is integrated into GitLab. Jenkins is a self-hosted, plugin-rich classic. CircleCI and Travis CI are cloud-based alternatives. Each tool has its own configuration format, but the concepts are the same: define your pipeline as code, trigger it automatically, and get fast feedback on every change.

CI/CD Maturity

Teams progress through CI/CD maturity levels. At the basic level, you have manual builds and deploys. Next, you add automated builds and tests on push. Then, you automate deployment to staging. Finally, you reach continuous deployment where every passing change goes to production automatically. Each level reduces risk and increases speed. The key is to start small — automate your test suite first, then add deployment automation incrementally. Measure your deployment frequency and lead time to track progress.

示例代码

              # A simple CI/CD pipeline concept (GitHub Actions style)
name: CI/CD Pipeline
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test
      - run: npm run build
      - run: docker build -t myapp:${{ github.sha }} .
            

这个流水线触发 on 推送到 主要, 安装 dependencies, 运行测试, 构建 app, and 创建 Docker 镜像 tagged 使用提交 SHA for traceability.

动手试一试

常见错误

错误写法

Skipping 测试到 速度上 流水线

正确做法

从不 skip 测试. 快流水线使用否 测试是 worse than 否流水线. Optimize 测试 execution 使用 parallelism and 缓存相反的 移除测试.

错误写法

Deploying directly 从构建分支

正确做法

构建 artifacts 一次 and promote 相同 artifact 通过环境. 构建 separately for 每个环境 introduces variability and defeats purpose 的 CI/CD.

练习 CI/CD Overview

2 个练习

练习 CI/CD Overview

查阅不认识的术语

新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。

查看术语表

动手做项目

通过引导式项目应用所学,含起始代码与解决方案。

查看项目

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误