You may need to send notifications to an external system after a workflow or a step in a workflow is complete. For example, you may want to send emails or instant messages (such as DingTalk messages) or use a message bus (such as Kafka) to notify the external system. This topic describes how to configure a workflow to send notifications to an external system. In this topic, DingTalk messages are used as an example.
Prerequisites
A Kubernetes cluster for distributed Argo workflows is created. The virtual private cloud (VPC) of the cluster has Internet access.
How it works
An external system usually receives messages by exposing an HTTP webhook.
Argo workflows support exit handlers. You can define
exit handlers
for the steps in a workflow or define anexit handler
for the workflow.Exit handlers run in containers. You can run the
curl
command in a container to send event notifications carried in HTTP messages to an external system.
Step 1: Create a DingTalk chatbot
After you create a DingTalk chatbot, a dedicated webhook URL is generated. You can associate the webhook URL with other services, such as Argo workflows, to receive notifications.
After you complete the configuration, record the webhook URL.
Step 2: Use the DingTalk chatbot in the workflow
Use the following YAML template to create a workflow and use the DingTalk chatbot in the workflow. For more information, see Create a workflow.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: notification-demo-
spec:
entrypoint: say-hello
onExit: exit-handler # Run the exit handler after the workflow is complete.
templates:
- name: say-hello
container:
image: alpine:latest
command: [sh, -c]
args: ["echo hello"]
- name: exit-handler
container:
image: curlimages/curl
command: [sh, -c]
# Run the curl command to send DingTalk messages and set the message type to link. You can include the link to the Argo workflow console to allow other users to quickly view the details of the workflow.
# The following variables can be referenced: {{workflow.name}}, {{workflow.status}}, {{workflow.failures}}, and {{workflow.workflow.duration}}.
args: [
"curl -H 'Content-Type: application/json' -d '{
\"msgtype\": \"link\",
\"link\": {
\"title\":\"Argo workflow notification\",
\"text\":\"WF {{workflow.name}} {{workflow.status}}\",
\"messageUrl\":\"https://argo.xxx.cn-zhangjiakou.alicontainer.com:2746/workflows/default/{{workflow.name}}?tab=workflow\"
}
}'
https://oapi.dingtalk.com/robot/send?access_token=b97fb519129fdfce879baa4e3b905b14e6a64e8994f0ea3b11dda****" #Replace it with the webhook URL of your DingTalk group.
]
The following figure shows an example of the DingTalk message.
References
For more information about how to integrate a custom chatbot with a system, see Integrate custom chatbots.