添加机器人
如何在群组中使用机器人?一、功能简介机器人 ( bot ) 是一种自动化的程序,可以向你自动推送消息,或与你进行简单的交互。你可以在群组中添加机器人,与团队成员实时共享消息,开展高效协作。例如,你可以利用飞书提醒机器人向团队成员发送提醒。注:一个群最多可添加 99 个机器人。 二、操作流程在群组中添加群机器人桌https://www.feishu.cn/hc/zh-CN/articles/360024984973
https://open.feishu.cn/open-apis/bot/v2/hook/bba16e19-55e9-4293-8c6b-e23ae2904cd8
消息通知
机器人概述
Jenkins 集成实践消息通知
注意: 为了获取构建用户的名称, 需要安装插件build user vars plugin
。
完整的Jenkinsfile:文章来源:https://www.toymoban.com/news/detail-640754.html
注意: 飞书的body中换行符要用双斜杠;(9499 参数错误)文章来源地址https://www.toymoban.com/news/detail-640754.html
pipeline{
agent { label "master"}
stages{
stage("Dingding"){
steps{
script {
wrap([$class: 'BuildUser']){
echo "full name is $BUILD_USER"
echo "user id is $BUILD_USER_ID"
echo "user email is $BUILD_USER_EMAIL"
env.BUILD_USER = "${BUILD_USER}"
}
if ("${env.msgType}" == "dingding") {
DingDing("${env.BUILD_USER}")
}
if ("${env.msgType}" == "weixin") {
WeiXin("${env.BUILD_USER}")
}
if ("${env.msgType}" == "feishu") {
FeiShu("${env.BUILD_USER}")
}
}
}
}
}
}
//飞书
def FeiShu(users){
sh """
curl --location --request POST 'https://open.feishu.cn/open-apis/bot/v2/hook/c9dde6d6-d4dc-405c-b1df-2dc2f448f49d' \
--header 'Content-Type: application/json' \
--data '{
"msg_type": "interactive",
"card": {
"config": {
"wide_screen_mode": true,
"enable_forward": true
},
"elements": [{
"tag": "div",
"text": {
"content": "## ${JOB_NAME}作业构建信息: \\n### 构建ID: ${BUILD_ID} \\n### 构建人:${users} \\n### 作业状态: ${currentBuild.currentResult} \\n### 运行时长: ${currentBuild.durationString} \\n###### 更多详细信息点击 [构建日志](${BUILD_URL}/console) \\n",
"tag": "lark_md"
}
}, {
"actions": [{
"tag": "button",
"text": {
"content": "作业链接",
"tag": "lark_md"
},
"url": "${JOB_URL}",
"type": "default",
"value": {}
}],
"tag": "action"
}],
"header": {
"title": {
"content": "DEVOPS作业构建信息",
"tag": "plain_text"
}
}
}
} '
"""
}
// 企业微信
def WeiXin(users){
withCredentials([string(credentialsId: 'b992073c-c06d-4794-b36c-b0a845255977', variable: 'ACCESS_TOKEN')]) {
sh """
curl --location --request POST 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${ACCESS_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"msgtype": "markdown",
"markdown": {
"content": "## ${JOB_NAME}作业构建信息: \n ### 构建ID: ${BUILD_ID} \n ### 构建人:${users} \n ### 作业状态: ${currentBuild.currentResult} \n ### 运行时长: ${currentBuild.durationString} \n ###### 更多详细信息点击 [构建日志](${BUILD_URL}/console) \n"
}
}'
"""
}
}
def DingDing(users){
withCredentials([string(credentialsId: 'b191eaa5-0bb7-40e2-bb0f-4d3ca8bad72f', variable: 'TOKEN')]) {
sh """
curl --location --request POST "https://oapi.dingtalk.com/robot/send?access_token=${TOKEN}" \
--header 'Content-Type: application/json' \
--data '{
"msgtype": "markdown",
"markdown": {
"title": "DEVOPS通知",
"text": "## ${JOB_NAME}作业构建信息: \n ### 构建ID: ${BUILD_ID} \n ### 构建人:${users} \n ### 作业状态: ${currentBuild.currentResult} \n ### 运行时长: ${currentBuild.durationString} \n ###### 更多详细信息点击 [构建日志](${BUILD_URL}/console) \n"
},
"at": {
"isAtAll": true
}
}'
"""
}
}
到了这里,关于Jenkins 飞书消息通知的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!