脚本主要去mysql查 项目的信息 比如:git地址 项目名 域名,最后调用钉钉 api token
再Jenkins上构建成功后 执行dingding.sh脚本通知到项目群所有研发人员。
#!/bin/bash
tag=$1
project_name=`echo $tag | awk -F "_" '{print $4}' | awk -F "-ALL" '{print $1}'`project_info=`mysql -h0.0.0.0 -ujenkins -p'xxxx' --skip-ssl -e "select git_addr from jenkins.backend_project_info_test where repository_name='$project_name' limit 1"`
gitaddr=`echo $project_info|awk -F 'git_addr' '{print$2}'`
date=`date "+%Y-%m-%d %H:%M"`
commit=`cd /opt/software/industry-jenkins/test/backend/code/$project_name/ && git log --pretty=format:"%h - %s" -1|awk '{print $NF}'`
prijectname=`mysql -h0.0.0.0 -ujenkins -p'xxxx' --skip-ssl --skip-column-names -e "select project_name from jenkins.backend_project_info_test where repository_name='$project_name' limit 1"`
url=`mysql -h0.0.0.0 -ujenkins -p'xxxx' --skip-ssl --skip-column-names -e "select host from jenkins.backend_project_info_test where repository_name='$project_name' limit 1"`
robot_webhook_url=https://oapi.dingtalk.com/robot/send
# 创建钉钉机器人告警
curl "${robot_webhook_url}" -H 'Content-Type: application/json' -d '
{
"at": {
"isAtAll":"true"
},
"msgtype": "text",
"text": {
"content": "'"时间: $date\n项目名:$prijectname-$project_name\n构建对象:后端\n优化点:$commit\n项目tag:$tag\n项目地址:https://$url:32443\n项目git地址:$gitaddr\n构建状态:成功"'"
}
}'
Jenkins构建成功 钉钉项目通知
于 2024-01-11 15:41:54 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)