kubevela.github.io/i18n/zh/docusaurus-plugin-content-docs/current/end-user/workflow/webhook-notification.md

3.9 KiB
Raw Blame History

title
使用 Webhook 发送通知

在一些情况下当我们使用工作流部署应用前后希望能够得到部署的通知。KubeVela 提供了与 Webhook 集成的能力,支持用户在工作流中向钉钉或者 Slack 发送通知。

本节将介绍如何在工作流中通过 webhook-notification 发送 Webhook 通知。

请确保你的 KubeVela 版本 >=v1.1.6

参数说明

参数 类型 说明
slack Object 可选值,如果需要发送 Slack 信息,则需填写其 url 及 message
slack.url Object 必填值Slack 的 Webhook 地址,可以选择直接填写或从 secret 中获取
slack.url.address String 可选值,直接填写 Slack 的 Webhook 地址
slack.url.fromSecret.name String 可选值, 从 secret 中获取 Webhook 地址secret 的名字
slack.url.fromSecret.key String 可选值, 从 secret 中获取 Webhook 地址,从 secret 中获取的 key
slack.message Object 必填值,需要发送的 Slack 信息,请符合 Slack 信息规范
dingding Object 可选值,如果需要发送钉钉信息,则需填写其 url 及 message
dingding.url Object 必填值,钉钉的 Webhook 地址,可以选择直接填写或从 secret 中获取
dingding.url.address String 可选值,直接填写钉钉的 Webhook 地址
dingding.url.fromSecret.name String 可选值, 从 secret 中获取 Webhook 地址secret 的名字
dingding.url.fromSecret.key String 可选值, 从 secret 中获取 Webhook 地址,从 secret 中获取的 key
dingding.message Object 必填值,需要发送的钉钉信息,请符合 钉钉信息规范

如何使用

部署如下应用部署计划,在部署组件前后,都有一个 webhook-notification 步骤发送通知:

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: first-vela-workflow
  namespace: default
spec:
  components:
  - name: express-server
    type: webservice
    properties:
      image: crccheck/hello-world
      port: 8000
    traits:
    - type: ingress
      properties:
        domain: testsvc.example.com
        http:
          /: 8000
  workflow:
    steps:
      - name: dingtalk-message
        # 指定步骤类型
        type: webhook-notification
        properties:
          dingding:
            # 钉钉 Webhook 地址请查看https://developers.dingtalk.com/document/robots/custom-robot-access
            url:
              address: <your dingding url>
            # 具体要发送的信息详情
            message:
              msgtype: text
              text:
                content: 开始运行工作流
      - name: application
        type: apply-component
        properties:
          component: express-server
        outputs:
          - from: app-status
            valueFrom: output.status.conditions[0].message + "工作流运行完成"
      - name: slack-message
        type: webhook-notification
        inputs:
          - name: app-status
            parameterKey: properties.slack.message.text
        properties:
          slack:
            # Slack Webhook 地址请查看https://api.slack.com/messaging/webhooks
            url:
              fromSecret:
                name: <the secret name that stores your slack url>
                key: <the secret key that stores your slack url>
            # 具体要发送的信息详情,会被 input 中的值覆盖
            # message:
            #   text: condition message + 工作流运行完成

期望结果

通过与 Webhook 的对接,可以看到,在工作流中的组件部署前后,都能在对应的群聊中看到相应的信息。

通过 webhook-notification ,可以使用户方便的与 Webhook 对接消息通知。