首页/开发/CI/CD 与发布速查/可复用流水线模板
流水线设计54 条

可复用流水线模板

把通用片段抽成模板:GitLab include/extends 与 CI 组件、GitHub 可复用工作流、Jenkins 共享库,避免复制粘贴漂移。

CI/CD 与发布速查开发更新于 2026-10-12
GitLabinclude(项目/远程/模板)+ extends 合并且可覆盖
GitHubworkflow_call 可复用工作流 + composite action 复合步骤
JenkinsShared Library(vars/ 下全局步骤)

GitHub 可复用工作流

GitHub 可复用工作流
# .github/workflows/build.yml(被复用)
on:
  workflow_call:
    inputs:
      node:
        type: string
jobs:
  build:
    runs-on: ubuntu-latest
    steps: [{run: echo "node ${{ inputs.node }}"}]

GitLab include

GitLab include
include:
  - project: 'platform/ci-templates'
    file: '/templates/node.yml'
模板仓库同样要版本化:引用固定标签或提交,避免上游改动波及所有项目。

易错点

  • 模板引用浮动分支:上游一改全部项目行为变化,应锁定版本
  • 复制粘贴模板后各自修改:修复无法回灌,定期收拢回模板

数据来源与参考

  • GitLab Docs《CI/CD components》
  • GitHub Docs《Reusing workflows》
  • Jenkins Docs《Extending with shared libraries》
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌