告警输出终端使用钉钉群机器人
只需要在pipeline的Jenkinsfile加入post failure的脚本代码
post {
failure {
echo "pipeline运行失败..."
script{
def content = """{"msgtype": "link","link": { "text": "序列号「${env.BUILD_NUMBER}」的CI流执行失败,点击卡片跳转到日志输出控制台。","title": "警告!项目「${env.JOB_NAME}」编译报错!","picUrl": "","messageUrl": "${env.BUILD_URL}/console"}}"""
sh "
curl 'https://oapi.dingtalk.com/robot/send?access_token=your_token'
-H 'Content-Type: application/json'
-d '$content'
"
}
}
}
钉钉机器人设置请参考:
一般会社员:监控与警报(一):grafana接入钉钉报警机器人zhuanlan.zhihu.com关于服务部署状态的通知请参考:
钉钉机器人相关语法:https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq
pipeline语法:https://www.jenkins.io/doc/book/pipeline/syntax/