$npx -y skills add TestAny-io/testany-agent-skills --skill testany-triggerTestany 执行入口与单次触发 - 为 pipeline 配置 Plan、Manual Trigger、Gatekeeper,或立即执行一次
| 1 | # Testany Trigger |
| 2 | |
| 3 | 管理 Testany 平台上的 **trigger**,并负责 **即时发起一次 pipeline execution**。 |
| 4 | |
| 5 | 用户输入: $ARGUMENTS |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | ## 先统一心智模型 |
| 10 | |
| 11 | 在开始之前,先按 [automation-model.md](../testany-guide/references/automation-model.md) 理解边界: |
| 12 | |
| 13 | - `pipeline` 是执行与编排单元 |
| 14 | - `trigger` 是执行入口 |
| 15 | - `trigger` 决定“如何发起 execution” |
| 16 | - `execution` 发起之后的观测与管理属于 `testany-execution` |
| 17 | |
| 18 | **重要结论**: |
| 19 | - 本 skill 既负责**持久化执行入口**,也负责**即时单次触发** |
| 20 | - 本 skill 不负责查看 execution 历史、轮询、取消或失败诊断 |
| 21 | |
| 22 | --- |
| 23 | |
| 24 | ## 职责范围 |
| 25 | |
| 26 | - 创建/查询/更新/删除 Plan(定时计划) |
| 27 | - 创建/查询/更新/删除 Gatekeeper(Webhook 触发器) |
| 28 | - 覆盖 Manual Trigger 的平台概念、适用场景和当前支持路径 |
| 29 | - 立即执行一次已有 pipeline(ad-hoc run now) |
| 30 | - 为已有 pipeline 提供合适的 trigger 方案建议 |
| 31 | - 提供可复制的 Webhook / CI 集成示例 |
| 32 | |
| 33 | --- |
| 34 | |
| 35 | ## Trigger 类型 |
| 36 | |
| 37 | ### Persistent Trigger |
| 38 | |
| 39 | 长期存在、可重复复用的执行入口: |
| 40 | - `Plan` |
| 41 | - `Manual Trigger` |
| 42 | - `Gatekeeper` |
| 43 | |
| 44 | ### Ad-hoc Trigger |
| 45 | |
| 46 | 一次性即时触发: |
| 47 | - `testany_execute_pipeline` |
| 48 | |
| 49 | 它会直接返回 `execution_key`,后续观测与管理交给 `testany-execution`。 |
| 50 | |
| 51 | --- |
| 52 | |
| 53 | ## MCP 支持现状 |
| 54 | |
| 55 | | 类型 | 平台能力 | 当前 MCP 支持 | 本 skill 的处理方式 | |
| 56 | |------|---------|--------------|--------------------| |
| 57 | | Plan | 完整 | 有 | 直接通过 MCP CRUD | |
| 58 | | Gatekeeper | 完整 | 有(含 pipeline 绑定与 webhook URL) | 直接通过 MCP 完成全流程 | |
| 59 | | Manual Trigger | 平台已支持 | 当前未看到对应 MCP tools | 明确纳入 trigger 体系;若当前宿主/MCP 无工具,则指导用户走 UI fallback | |
| 60 | | Run Now | 完整 | 有 (`testany_execute_pipeline`) | 直接执行一次并返回 `execution_key` | |
| 61 | |
| 62 | --- |
| 63 | |
| 64 | ## 操作速查 |
| 65 | |
| 66 | ### Persistent Trigger |
| 67 | |
| 68 | | 用户意图 | 操作类型 | MCP 工具 | |
| 69 | |---------|---------|---------| |
| 70 | | 列出 Gatekeepers | Read | `testany_list_gatekeepers` | |
| 71 | | 查看 Gatekeeper 详情 | Read | `testany_get_gatekeeper` | |
| 72 | | 创建 Gatekeeper | Create | `testany_create_gatekeeper`(可同时绑定 pipelines) | |
| 73 | | 查看 Gatekeeper 绑定的 Pipelines | Read | `testany_get_gatekeeper_pipelines` | |
| 74 | | 绑定/替换 Gatekeeper 的 Pipelines | Update | `testany_bind_gatekeeper_pipelines` | |
| 75 | | 更新 Gatekeeper 字段 | Update | `testany_update_gatekeeper` | |
| 76 | | 删除 Gatekeeper | Delete | `testany_delete_gatekeeper` | |
| 77 | | 列出 Plans | Read | `testany_list_plans` | |
| 78 | | 查看 Plan 详情 | Read | `testany_get_plan` | |
| 79 | | 创建 Plan | Create | `testany_create_plan` | |
| 80 | | 更新 Plan | Update | `testany_update_plan` | |
| 81 | | 删除 Plan | Delete | `testany_delete_plan` | |
| 82 | | 转移 Plan Owner | Update | `testany_assign_plan` | |
| 83 | |
| 84 | 常用辅助: |
| 85 | - `testany_get_my_workspaces` |
| 86 | - `testany_list_pipelines` |
| 87 | |
| 88 | ### Ad-hoc Run Now |
| 89 | |
| 90 | | 用户意图 | MCP 工具 | |
| 91 | |---------|---------| |
| 92 | | 立即执行一次 pipeline | `testany_execute_pipeline` | |
| 93 | |
| 94 | --- |
| 95 | |
| 96 | ## Trigger 选择原则 |
| 97 | |
| 98 | | 方式 | 适用场景 | |
| 99 | |------|---------| |
| 100 | | Plan | 固定时间自动执行,如夜间回归、定时巡检 | |
| 101 | | Manual Trigger | 人工按需执行,如修复后复测、发布前验收 | |
| 102 | | Gatekeeper | 外部事件驱动执行,如 CI/CD、告警、Webhook | |
| 103 | | Run Now | 现在立刻执行一次,不沉淀长期 trigger 资源 | |
| 104 | |
| 105 | --- |
| 106 | |
| 107 | ## Run Now(立即执行一次) |
| 108 | |
| 109 | ### 适用场景 |
| 110 | |
| 111 | - “现在帮我跑一次这个 pipeline” |
| 112 | - “临时执行一次回归” |
| 113 | - “刚改完,立即验证” |
| 114 | |
| 115 | ### 流程 |
| 116 | |
| 117 | 1. 如果用户没有明确 pipeline key: |
| 118 | - `testany_get_my_workspaces` |
| 119 | - `testany_list_pipelines` |
| 120 | - 帮用户定位目标 pipeline |
| 121 | 2. 调用 `testany_execute_pipeline` |
| 122 | 3. 返回 `execution_key` |
| 123 | 4. 明确告诉用户: |
| 124 | - 执行已经发起 |
| 125 | - 接下来如需看进度、查历史、取消、看结果,切到 `testany-execution` |
| 126 | |
| 127 | ### 输入补充 |
| 128 | |
| 129 | 如有需要,可同时传: |
| 130 | - `environment` |
| 131 | - `parameters` |
| 132 | |
| 133 | 但不要把这些一次性参数误写成长期 trigger 配置。 |
| 134 | |
| 135 | --- |
| 136 | |
| 137 | ## Plan(定时计划) |
| 138 | |
| 139 | ### 定义 |
| 140 | |
| 141 | Plan 用于按固定 schedule 自动触发一个或多个 pipeline。 |
| 142 | |
| 143 | ### 创建流程 |
| 144 | |
| 145 | 1. `testany_get_my_workspaces` → 选择 workspace |
| 146 | 2. `testany_list_pipelines` → 选择要定时执行的 pipelines |
| 147 | 3. `testany_create_plan` → 创建计划 |
| 148 | |
| 149 | 建议同时填写: |
| 150 | - `schedule_expr` |
| 151 | - `timezone` |
| 152 | - `schedule_str` |
| 153 | - `watchers` |
| 154 | |
| 155 | ### 更新注意事项 |
| 156 | |
| 157 | Plan 更新应视为高风险“覆盖式更新”: |
| 158 | 1. `testany_get_plan` 先读取现有配置 |
| 159 | 2. 基于现有配置构造完整 payload |
| 160 | 3. 再调用 `testany_update_plan` |
| 161 | |
| 162 | --- |
| 163 | |
| 164 | ## Manual Trigger(按需执行模板) |
| 165 | |
| 166 | ### 定义 |
| 167 | |
| 168 | Manual Trigger 用于按需执行一个或多个 pipeline,不依赖定时调度,也不依赖外部 webhook。 |
| 169 | |
| 170 | ### 典型场景 |
| 171 | |
| 172 | - 热修复上线前快速回归 |
| 173 | - 环境恢复后立即复测关键链路 |
| 174 | - 人工发起标准化多 pipeline 验收 |
| 175 | |
| 176 | ### 当前处理方式 |
| 177 | |
| 178 | 如果当前 MCP/宿主没有 Manual Trigger 工具: |
| 179 | 1. 帮用户确定 workspace 和 pipelines |
| 180 | 2. 给出建议的名称、描述和 pipeline 列表 |
| 181 | 3. 提示用户到 Testany UI 创建 Manual Trigger |
| 182 | |
| 183 | --- |
| 184 | |
| 185 | ## Gatekeeper(Webhook / 事件驱动) |
| 186 | |
| 187 | ### 定义 |
| 188 | |
| 189 | Gatekeeper 通过 Webhook 触发一个 pipeline group 的执行。 |
| 190 | |
| 191 | ### 重要澄清 |
| 192 | |
| 193 | - Gatekeeper 不是 pipeline 编排工具 |
| 194 | - Gatekeeper 不是 execution 观测工具 |
| 195 | - “是否放行部署”属于外部 CI/CD 逻辑,应在调用 Gatekeeper 之后依据 execution 结果自行决定 |
| 196 | |
| 197 | ### 创建流程 |
| 198 | |
| 199 | **方式一:创建时直接绑定(推荐)** |
| 200 | 1. `testany_get_my_workspaces` → 选择 workspace |
| 201 | 2. `testany_list_pipelines` → 选择要触发的 pipelines |
| 202 | 3. `testany_create_gatekeeper(workspace, name, pipelines=[...])` → 创建并绑定 |
| 203 | 4. `testany_get_gatekeeper` → 获取 `hook_url` |
| 204 | 5. `testany_update_gatekeeper` → 配置 trigger_method / trigger_name / trigger_condition / watchers / owned_by |
| 205 | |
| 206 | **方式二:先创建,再绑定** |
| 207 | 1. `testany_create_gatekeeper` → 创建 Gatekeeper |
| 208 | 2. `testany_bind_gatekeeper_pipelines` → 绑定 pipelines |
| 209 | 3. `testany_get_gatekeeper_pipelines` → 确认绑定结果 |
| 210 | |
| 211 | ### Webhook URL 获取 |
| 212 | |
| 213 | 通过 `testany_get_gatekeeper` 获取详情即可拿到 `hook_url`。如果用户无编辑权限,`hook_url` 会是 null。 |
| 214 | |
| 215 | --- |
| 216 | |
| 217 | ## CI/CD 集成示例 |
| 218 | |
| 219 | ### GitHub Actions |
| 220 | |
| 221 | ```yaml |
| 222 | - name: Trigger Testany Gatekeeper |
| 223 | run: | |
| 224 | curl -X POST "${{ secrets.TESTANY_GATEKEEPER_WEBHOOK_URL }}" \ |
| 225 | -H "Content-Type: application/json" \ |
| 226 | -d '{"source":"github-actions"}' |
| 227 | ``` |
| 228 | |
| 229 | ### Jenkins |
| 230 | |
| 231 | ```groovy |
| 232 | stage('Quality Gate') { |
| 233 | steps { |
| 234 | sh ''' |
| 235 | curl -X POST "${TESTANY_GATEKEEPER_WEBHOOK_URL}" \ |
| 236 | -H "Content-Type: application/json" \ |
| 237 | -d '{"source":"jenkins"}' |