从 Jenkins 迁移到 GitHub Actions

从自托管 Jenkins 迁移到云托管 GitHub Actions 的完整指南

Estimated time: 2-4 周(视 Pipeline 复杂度) Difficulty: Medium

Migration Steps

评估与规划
Estimated time: 3-5 天
  • 梳理现有 Jenkins Pipeline 列表和依赖关系
  • 确认 GitHub Actions 是否有对应的 Action 替代 Jenkins 插件
  • 评估自托管 Runner 需求(特殊环境/GPU/内网部署)
  • 制定迁移优先级:先简单 Pipeline,后复杂 Pipeline
  • 通知团队迁移计划,安排培训时间
Pipeline 转换
Estimated time: 5-7 天
  • 将 Jenkinsfile 声明式语法转换为 GitHub Actions YAML
  • 替换 Jenkins 插件为对应的 GitHub Actions(从 Marketplace 查找)
  • 配置 GitHub Secrets 替代 Jenkins Credentials
  • 设置 Environment 和部署保护规则
  • 配置矩阵构建替代 Jenkins 多配置项目
集成迁移
Estimated time: 3-5 天
  • 配置 Docker 构建和推送流程
  • 设置部署目标(AWS/Azure/GCP/K8s)
  • 迁移通知集成(Slack/钉钉/邮件)
  • 配置制品存储(GitHub Packages 或外部仓库)
  • 设置自托管 Runner(如需内网部署)
验证与切换
Estimated time: 3-5 天
  • 在非生产环境并行运行两套 CI/CD 对比结果
  • 验证构建产物一致性
  • 全员培训 GitHub Actions 基础操作和调试方法
  • 正式切换生产 Pipeline 到 GitHub Actions
  • 保留 Jenkins 只读运行 2 周作为回退

Risks & Mitigation

插件功能缺失

提前在 GitHub Marketplace 搜索替代 Action,必要时编写自定义 Action

构建时间变长

利用缓存(actions/cache)、矩阵构建并行、自托管 Runner 加速

Secrets 泄露风险

使用 GitHub Environments 限制 Secret 访问范围,启用审计日志

复杂 Pipeline 转换困难

将复杂 Jenkinsfile 拆分为多个 Workflow,利用 reusable workflows 复用

查看 Jenkins Details → 查看 GitHub Actions Details →