jenkins把自动化测试结果发送到钉钉群
原创
©著作权归作者所有:来自51CTO博客作者全栈测试笔记的原创作品,请联系作者获取转载授权,否则将追究法律责任
添加钉钉机器人
创建钉钉群
![jenkins把自动化测试结果发送到钉钉群_javascript](https://s2.51cto.com/images/blog/202210/01013404_6337288ca8e4839833.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
群设置
![jenkins把自动化测试结果发送到钉钉群_javascript_02](https://s2.51cto.com/images/blog/202210/01013404_6337288cdafea66084.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
智能群助手
![jenkins把自动化测试结果发送到钉钉群_自动化测试_03](https://s2.51cto.com/images/blog/202210/01013404_6337288cee95832644.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
添加机器人
![jenkins把自动化测试结果发送到钉钉群_自动生成_04](https://s2.51cto.com/images/blog/202210/01013405_6337288d130ca2218.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
添加机器人
![jenkins把自动化测试结果发送到钉钉群_自动生成_05](https://s2.51cto.com/images/blog/202210/01013405_6337288d27f2981525.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
自定义
![jenkins把自动化测试结果发送到钉钉群_自动化测试_06](https://s2.51cto.com/images/blog/202210/01013405_6337288d6a83041822.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
添加
![jenkins把自动化测试结果发送到钉钉群_自动生成_07](https://s2.51cto.com/images/blog/202210/01013405_6337288d8d04856079.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
输入机器人名字、勾选“加签”
SEC6ff2263d59de4d4db749fc368ab9352b375334fabc2e815e176f0a777e3596c8
![jenkins把自动化测试结果发送到钉钉群_自动生成_08](https://s2.51cto.com/images/blog/202210/01013405_6337288dab11165656.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
Webhook
https://oapi.dingtalk.com/robot/send?access_token=b3c95b7cc50da0dcce2d5a2bea4834369bfe83603a2e3980957dc89250ae70b5
![jenkins把自动化测试结果发送到钉钉群_javascript_09](https://s2.51cto.com/images/blog/202210/01013405_6337288dbdd3378002.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
设置说明:https://open.dingtalk.com/document/robots/custom-robot-access
添加成功
![jenkins把自动化测试结果发送到钉钉群_自动生成_10](https://s2.51cto.com/images/blog/202210/01013405_6337288dd3a9933276.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
添加成功的消息
![jenkins把自动化测试结果发送到钉钉群_javascript_11](https://s2.51cto.com/images/blog/202210/01013405_6337288dea85513556.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
安装插件及配置
![jenkins把自动化测试结果发送到钉钉群_javascript_12](https://s2.51cto.com/images/blog/202210/01013406_6337288e10c9f11671.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
系统配置
![jenkins把自动化测试结果发送到钉钉群_自动化测试_13](https://s2.51cto.com/images/blog/202210/01013406_6337288e22c0883926.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
![jenkins把自动化测试结果发送到钉钉群_javascript_14](https://s2.51cto.com/images/blog/202210/01013406_6337288e3711330348.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
下面id可以不填写,保存后会自动生成
![jenkins把自动化测试结果发送到钉钉群_自动生成_15](https://s2.51cto.com/images/blog/202210/01013406_6337288e4dc6424246.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
![jenkins把自动化测试结果发送到钉钉群_自动生成_16](https://s2.51cto.com/images/blog/202210/01013406_6337288e6486232893.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
测试成功
![jenkins把自动化测试结果发送到钉钉群_自动化测试_17](https://s2.51cto.com/images/blog/202210/01013406_6337288e7a99b59076.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
保存后再次打开,可以看到自动生成的id
![jenkins把自动化测试结果发送到钉钉群_自动化测试_18](https://s2.51cto.com/images/blog/202210/01013406_6337288e8e8d419265.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
我们这里修改一下,方便我们记忆,以及后续在pipeline中使用
![jenkins把自动化测试结果发送到钉钉群_自动化测试_19](https://s2.51cto.com/images/blog/202210/01013406_6337288ea84ce25151.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
配置pipeline任务
如果用pipeline,下面都取消勾选,否则构建启动、结束,都会发通知,我们只需要发送我们定义的通知即可
![jenkins把自动化测试结果发送到钉钉群_自动化测试_13](https://s2.51cto.com/images/blog/202210/01013406_6337288e22c0883926.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
![jenkins把自动化测试结果发送到钉钉群_javascript_21](https://s2.51cto.com/images/blog/202210/01013406_6337288ece63d89063.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
job中,下面也不配置
![jenkins把自动化测试结果发送到钉钉群_自动化测试_22](https://s2.51cto.com/images/blog/202210/01013406_6337288ee279652355.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
![jenkins把自动化测试结果发送到钉钉群_自动化测试_23](https://s2.51cto.com/images/blog/202210/01013407_6337288f0277754147.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
效果展示
pipeline job构建后,电脑右下角收到钉钉通知
![jenkins把自动化测试结果发送到钉钉群_自动生成_24](https://s2.51cto.com/images/blog/202210/01013407_6337288f15c5b77518.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
消息内容:可以配置,比如点击超链接查看测试报告等
![jenkins把自动化测试结果发送到钉钉群_自动化测试_25](https://s2.51cto.com/images/blog/202210/01013407_6337288f2b07771124.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
附:pipeline
说明:这里只是一个测试钉钉消息的简单示例
pipeline {
agent any
stages {
stage("test"){
steps {
sh """
echo "WORKSPACE: ${WORKSPACE}"
"""
}
post {
success {
dingtalk (
robot:'dd01',
type:'MARKDOWN',
atAll: true,
title: "notice: 自动化测试完成",
text: ["#### '${JOB_NAME}'项目自动化测试完成\n - 任务:第'${BUILD_NUMBER}'次\n - 状态:'${currentBuild.result}'\n - [查看job](${JOB_URL})"]
)
}
}
}
}
}