来源: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.
- Infrastructure: A CI platform with the claude-code-action installed, or any runner that can call
claude -p; model access through the API, or Amazon Bedrock, Microsoft Foundry, or Vertex AI where traffic must stay on the organization’s cloud agreement; MCP servers for the deployment targets; a sandbox profile for agent jobs with no standing production credentials.
ZH 先决条件:PR 审查循环里的 AI,以及 hooks 当审批闸门——自动化加速任何东西穿过闸门之前,闸门必须先在。
- 基础设施:装了 claude-code-action 的 CI,或任何能调
claude -p的 runner;经 API 访问模型,或流量必须留在组织云协议里时用 Amazon Bedrock、Microsoft Foundry、Vertex AI;部署目标的 MCP 服务器;给 agent 任务的沙箱配置,默认没有长期生产凭据。
怎么做 / 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.
- The production deploy hook blocks the release until a named release manager authorizes it. Each non-interactive run acts under the agent’s own identity, so the pipeline log separates what the agent did from what the engineer who triggered it did.
- Per-environment permission tiers set how much the agent may do on the way to the gate.
ZH 分支保护 把 agent 写的任何东西变成 PR,没有直通 main 的路。
- 生产部署 hook 拦住发布,直到点名的发布经理授权。每次非交互跑都用 agent 自己的身份,流水线日志把 agent 做的和触发它的工程师做的分开。
- 按环境的权限档 设定通往闸门的路上 agent 能做多少。
怎么衡量 / How to measure it
EN - Leading indicator: The share of pipeline failures triaged without paging a human, taken from the CI/CD pipeline logs.
- Lagging indicator: DevOps Research and Assessment (DORA) measures, which the CI system and deployment tooling already emit.
ZH 领先指标:不叫人就分流完的流水线失败占比,从 CI/CD 流水线日志读。
- 滞后指标:DORA(DevOps Research and Assessment)指标,CI 系统和部署工具已经在吐。
读完能记住的三句话
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 环真正需要前回滚。