跳到正文
小马哥的博客
返回

CI/CD 集成和发布

来源:https://academy.claude.com/courses/ai-native-sdlc-playbook/ci-cd-integration-and-deployment 读这篇之前:10 PR 审查 + 11 hooks(闸门必须先在) 不确定:ZH 是 Clint 译官方英文课体,不是 Anthropic 中文。

本课词汇

English中文怎么记
claude -p非交互 prompt流水线里跑 Claude,没人坐在旁边
sandbox沙箱网络策略、短命令牌、默认没有生产凭据
MCP模型上下文协议把部署、状态、回滚暴露成工具允许名单
DORA四项交付指标课说 CI 和部署工具已经在吐
rollback回滚流水线里排练最多的那条路,越界时会调

对照正文

EN Run Claude Code non-interactively inside the CI/CD pipeline, sandbox the execution so long-running agents run safely, expose deployment through MCP integrations, and rehearse the rollback paths before the agent ever needs them.

ZH 在 CI/CD 流水线里非交互跑 Claude Code,把执行沙箱化让长跑 agent 安全,用 MCP 暴露部署,并在 agent 真正需要前回滚路径。

什么变了 / What changes

EN | Traditional | AI-native | | --- | --- | | Pipelines run deterministic scripts, and anything that needs judgment waits for a human: for example, triaging the flaky test, writing the changelog, or working out why the build broke. Deployment and rollback are runbooks a human follows under pressure. | Claude runs non-interactively inside the pipeline for the judgment steps, in a sandbox with scoped credentials. Deployment tooling is exposed to the agent through MCP, so the workflow that wrote and tested the change can also ship it and roll it back, inside gates the organization defines per environment. |

ZH | 传统 | AI-native | | --- | --- | | 流水线跑确定性脚本,需要判断的等着人:例如分流脆弱测试、写 changelog、查明构建为何坏了。部署和回滚是人在压力下照着的 runbook。 | Claude 在流水线里非交互跑判断步骤,沙箱加范围凭据。部署工具经 MCP 暴露给 agent,于是写出并测过这次改动的工作流,也能在组织按环境定义的闸门内发布和回滚。 |

怎么起步 / Getting started

EN - Prerequisites: AI in the PR review loop and hooks as approval gates, because the gates must exist before automation accelerates anything through them.

ZH 先决条件:PR 审查循环里的 AI,以及 hooks 当审批闸门——自动化加速任何东西穿过闸门之前,闸门必须先在。

怎么做 / How to execute it

EN 1. The platform engineer starts with read-only judgment steps. Use claude -p in a pipeline job to triage a failed build, summarize a flaky test, or draft the changelog. 2. Add write steps behind the existing gates for jobs like fixing lint, updating generated docs, or addressing review comments via the @claude mentions. Anything the agent writes arrives as a PR through branch protection, and the agent has no route to push to main. 3. Execution is sandboxed. Agent jobs run in containers under a network policy with short-lived scoped tokens, and hold no production credentials by default. 4. Expose deployment through MCP. Deploy, status, and rollback become tools, scoped per environment, so the agent’s deployment powers are an allowlist rather than a shell script with credentials. 5. Tier the autonomy by environment. In development, the agent deploys freely. In production, the agent prepares the release and the release manager authorizes it, and a hook enforces the production gate. Staging sits somewhere in the middle. 6. Rollback should be the most rehearsed path in the pipeline, a single command that the agent can run and that is exercised regularly in staging. The closing the loop play (Stage 6: Maintain) calls this rollback when a control band is breached, so it has to be proven in advance.

ZH 1. 平台工程师从只读判断步骤开始。流水线任务里用 claude -p 分流失败构建、总结脆弱测试、或起草 changelog。 2. 在现有闸门后面加写入步骤,例如修 lint、更新生成文档、或经 @claude 处理审查评论。agent 写的任何东西都以 PR 进来,走 branch protection,agent 没有直推 main 的路。 3. 执行要沙箱化。Agent 任务跑在带网络策略的容器里,短命范围令牌,默认不持有生产凭据。 4. 经 MCP 暴露部署。部署、状态、回滚变成工具,按环境收范围,于是 agent 的部署能力是一份允许名单,不是带凭据的 shell 脚本。 5. 按环境分自主程度。开发环境 agent 随便部署。生产环境 agent 准备发布,发布经理授权,hook 强制生产闸。预发在中间某处。 6. 回滚应是流水线里排练最多的路径:一条 agent 能跑的命令,并在预发定期演练。闭合打法(Stage 6: Maintain)在控制带越界时会调这条回滚,所以必须事先证明。

长什么样 / What it looks like

EN Pipeline step:

ZH 流水线步骤:

- name: Triage failed build
  if: failure()
  run: >
    claude -p "Read the build log at out/build.log. Identify the most
    likely cause, say whether the failure looks flaky or real, and write a
    three-line summary for the PR thread." >> triage.md

ZH 官方示例,保持英文。

治理 / Governance considerations

EN The governing principle is that the agent may act up to the production gate and cannot pass it. The controls below enforce this principle.

ZH 治理原则:agent 可以干到生产闸为止,过不去。下面的控制强制这条原则。

EN - Branch protection turns anything the agent writes into a PR, with no direct path to main.

ZH 分支保护 把 agent 写的任何东西变成 PR,没有直通 main 的路。

怎么衡量 / How to measure it

EN - Leading indicator: The share of pipeline failures triaged without paging a human, taken from the CI/CD pipeline logs.

ZH 领先指标:不叫人就分流完的流水线失败占比,从 CI/CD 流水线日志读。

读完能记住的三句话

EN The agent may act up to the production gate and cannot pass it. ZH agent 可以干到生产闸为止,过不去。

EN Anything the agent writes arrives as a PR. There is no path to main. ZH agent 写的任何东西都以 PR 进来。没有直通 main 的路。

EN Rehearse rollback before the loop needs it. ZH 环真正需要前回滚。


分享这篇文章:

上一篇
Hooks 当审批闸门
下一篇
用指标把环闭合