You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在DroneCI流水线中添加审批阶段?请求提供Test→Approve(手动输入)→Prod受控多环境构建流水线的实现方案

Got it, I've set up exactly this kind of manual approval flow in DroneCI before—let me walk you through two reliable ways to implement your Test → Approve → Prod pipeline.

方法1:使用Drone内置的Promote功能(最简单直接)

This is the go-to approach for basic manual gatekeeping between stages. You define your test stage to run automatically, then lock your production deployment to only trigger when you manually "promote" the pipeline through the Drone UI.

Here's a sample .drone.yml configuration:

kind: pipeline
type: docker
name: default

steps:
  - name: run-tests
    image: your-test-image:latest # 替换成你的测试环境镜像,比如node、golang等
    commands:
      - npm test # 替换成你的实际测试命令
    when:
      event: [push, pull_request] # 代码推送或PR时自动运行测试

  - name: deploy-to-production
    image: your-deployment-image:latest # 替换成你的部署镜像
    commands:
      - ./deploy-prod.sh # 替换成你的实际部署命令
    when:
      event: promote # 仅当手动触发Promote事件时运行
      target: prod # 指定目标环境为prod,避免误触发到其他环境

如何操作:

  1. 当测试阶段成功完成后,你会在Drone的流水线详情页面看到一个Promote按钮。
  2. 点击按钮,在弹出的选项里选择prod作为目标环境,确认后就会触发生产部署阶段。

方法2:使用Approval插件(适合复杂审批逻辑)

If you need more control—like requiring multiple team members to approve, or restricting approval to specific users/teams—use Drone's official drone-approval plugin. This adds an explicit approval step that blocks the pipeline until authorized users sign off.

Sample configuration:

kind: pipeline
type: docker
name: default

steps:
  - name: run-tests
    image: your-test-image:latest
    commands:
      - npm test

  - name: approve-production-deployment
    image: drone/drone-approval
    settings:
      from:
        - team: admins # 指定允许审批的团队
        - user: nitin_g # 或者指定单个用户
      subject: "Approve Production Deployment"
      message: "Test results passed—please review and approve to deploy to prod."
    when:
      branch: main # 仅在主分支触发审批

  - name: deploy-to-production
    image: your-deployment-image:latest
    commands:
      - ./deploy-prod.sh
    when:
      status: success # 只有审批通过(状态为success)才会运行

如何操作:

  1. 测试阶段完成后,审批步骤会进入"pending"状态。
  2. 指定的用户/团队成员会在Drone的通知中心看到审批请求,或者直接在流水线页面找到该步骤,点击Approve按钮。
  3. 一旦审批通过,后续的生产部署阶段会自动启动。

关键注意事项

  • 权限配置: 确保你的Drone用户账号有promoteapprove权限(在Drone的组织/项目权限设置里配置)。
  • 环境隔离: 用targetbranch条件严格限制生产部署的触发场景,避免误操作。
  • 插件兼容性: 如果使用drone-approval插件,确保你的Drone server版本和插件版本匹配(插件支持Drone 1.x及以上版本)。

内容的提问来源于stack exchange,提问作者Nitin G

火山引擎 最新活动