理解“通知” 中的 Webhook包含的负载

Testany 通知系统当前会通过 Webhook 分发 发送如下精简 JSON 负载。 这个 webhook body 对应的是当前 Notification Gateway -> mailman-plugin 对执行事件数据的投影。 当前顶层字段固定为:

  • name
  • status
  • trigger_key
  • trigger_id
  • trigger_instance_key
  • trigger_method
  • trigger_owner
  • pipelines
  • payload

表 1:负载请求的基本信息

HTTP 版本HTTP/1.1
请求方法POST,符合 RFC2616
TLS 验证严格,如果提供
MIME 类型application/json
超时15 秒
重试3 次
主体见表 2

表 2:负载主体数据格式

类型说明示例
name字符串触发器资源的名称。"notification-demo-payload"
status整数触发实例的执行状态码。对“执行完成”通知,常见终态值有 1 成功、2 失败、3 跳过、5 已取消、99 错误。历史或非终态值还可能出现 -1 未开始、0 运行中。1
trigger_key字符串触发器资源的键。"P-ABC-0001"
trigger_id字符串该触发器资源下某次具体触发实例的标识符。"033CE"
trigger_instance_key字符串具体触发实例的键。"P-ABC-0001-033CE"
trigger_method字符串,枚举指示触发器类型。枚举:plangatekeepermanual_trigger"plan"
trigger_owner[]字符串触发器资源所有者的列表。["[email protected]"]
pipelines[]管道执行的管道列表。见表 3
payload字符串从触发源透传下来的可选自定义负载,按原样作为字符串传递;如果没有自定义负载,则为空字符串。"opaque-string-payload"

表 3:管道数据格式

类型说明示例
name字符串管道的名称"demo-for-event"
status整数管道执行状态码。常见终态值有 1 成功、2 失败、3 跳过、5 已取消、99 错误。非终态值还可能出现 -1 未开始、0 运行中。1
key字符串管道的键。"ABC-0001"
owner[]字符串管道所有者的列表。["[email protected]"]
cases[]案例管道使用的案例执行结果列表。见表 4
duration整数管道执行的持续时间,单位为 22
execution_key字符串管道执行标识符。"ABC-0001-033CE"
start_time字符串,时间戳RFC3339 时间戳,指示管道执行的开始时间。"2006-01-02T15:04:05Z"
finish_time字符串,时间戳RFC3339 时间戳,指示管道执行的结束时间。"2006-01-02T15:04:05Z"

表 4:案例数据格式

类型说明示例
name字符串测试案例的名称"check-notification-active"
status整数测试案例执行状态码。常见终态值有 1 通过、2 失败、3 跳过、4 预期失败、5 已取消、99 错误。非终态值还可能出现 -1 未开始、0 运行中。1
case_index整数该案例执行在管道执行详情中的从 0 开始的位置索引。可与 execution_key 组合使用以打开对应的案例执行日志。0
key字符串测试案例的键。"00000000"
runtime_uuid字符串执行案例的运行时实例的唯一标识符。"00000000-0000-0000-0000-000000000000"
runtime_name字符串执行案例的运行时实例的唯一名称。"CloudPrime-Default"
owner[]字符串测试案例所有者的列表。["[email protected]"]
duration整数测试案例执行的持续时间,单位为 6
env字符串测试案例的环境"DEMO"
start_time字符串,时间戳RFC3339 时间戳,指示测试案例执行的开始时间。"2006-01-02T15:04:05Z"
finish_time字符串,时间戳RFC3339 时间戳,指示测试案例执行的结束时间。"2006-01-02T15:04:05Z"

示例

计划任务执行结果通知样例

JSON
{
  "name": "notification-demo-payload",
  "pipelines": [
    {
      "cases": [
        {
          "case_index": 0,
          "duration": 6,
          "env": "DEMO",
          "finish_time": "2006-01-02T15:04:05Z",
          "key": "00000000",
          "name": "check-notification-active",
          "owner": [
            "[email protected]"
          ],
          "start_time": "2006-01-02T15:04:05Z",
          "status": 1,
          "runtime_uuid": "00000000-0000-0000-0000-000000000000",
          "runtime_name": "CloudPrime-Default"
        }
      ],
      "duration": 22,
      "execution_key": "ABC-0001-033CE",
      "finish_time": "2006-01-02T15:04:05Z",
      "key": "ABC-0001",
      "name": "demo-for-event",
      "owner": [
        "[email protected]"
      ],
      "start_time": "2006-01-02T15:04:05Z",
      "status": 1
    }
  ],
  "payload": "opaque-string-payload",
  "status": 1,
  "trigger_key": "P-ABC-0001",
  "trigger_id": "033CE",
  "trigger_instance_key": "P-ABC-0001-033CE",
  "trigger_method": "plan",
  "trigger_owner": [
    "[email protected]"
  ]
}

门卫执行结果通知样例

JSON
{
  "name": "notification-demo-payload",
  "pipelines": [
    {
      "cases": [
        {
          "case_index": 0,
          "duration": 6,
          "env": "DEMO",
          "finish_time": "2006-01-02T15:04:05Z",
          "key": "00000000",
          "name": "check-notification-active",
          "owner": [
            "[email protected]"
          ],
          "start_time": "2006-01-02T15:04:05Z",
          "status": 1,
          "runtime_uuid": "00000000-0000-0000-0000-000000000000",
          "runtime_name": "CloudPrime-Default"
        }
      ],
      "duration": 22,
      "execution_key": "ABC-0001-033CE",
      "finish_time": "2006-01-02T15:04:05Z",
      "key": "ABC-0001",
      "name": "demo-for-event",
      "owner": [
        "[email protected]"
      ],
      "start_time": "2006-01-02T15:04:05Z",
      "status": 1
    }
  ],
  "payload": "opaque-string-payload",
  "status": 1,
  "trigger_key": "G-ABC-0001",
  "trigger_id": "033CE",
  "trigger_instance_key": "G-ABC-0001-033CE",
  "trigger_method": "gatekeeper",
  "trigger_owner": [
    "[email protected]"
  ]
}

手动触发执行结果通知样例

JSON
{
  "name": "manual-rerun-demo",
  "pipelines": [
    {
      "cases": [
        {
          "case_index": 0,
          "duration": 6,
          "env": "DEMO",
          "finish_time": "2006-01-02T15:04:05Z",
          "key": "00000000",
          "name": "check-notification-active",
          "owner": [
            "[email protected]"
          ],
          "start_time": "2006-01-02T15:04:05Z",
          "status": 1,
          "runtime_uuid": null,
          "runtime_name": null
        }
      ],
      "duration": 22,
      "execution_key": "ABC-0001-033CE",
      "finish_time": "2006-01-02T15:04:05Z",
      "key": "ABC-0001",
      "name": "demo-for-event",
      "owner": [
        "[email protected]"
      ],
      "start_time": "2006-01-02T15:04:05Z",
      "status": 1
    }
  ],
  "payload": "",
  "status": 1,
  "trigger_key": "M-ABC-0001",
  "trigger_id": "033CE",
  "trigger_instance_key": "M-ABC-0001-033CE",
  "trigger_method": "manual_trigger",
  "trigger_owner": [
    "[email protected]"
  ]
}

还有疑问?

我们的团队随时为您服务。欢迎联系我们,我们会尽快回复。