jenkins 配置钉钉通知

目的:配置钉钉通知,实现定时自动发布通知。

1.配置钉钉聊天组,添加机器人

 

 

 

 

我这边通过关键字 "构建" 生成 调用api。

我这边生成的api地址如下:https://oapi.dingtalk.com/robot/send?access_token=5d0dc954f00b717ab3cc44ff2a3eb41da355eb57aaxxxxxxxxxxxxx'

2.jenkins 添加插件,获取user 相关变量

 

 

 安装完重启jenkins。

以下是jenkins user相关的变量:

 

3.配置jenkins 调用钉钉api 命令 (注:我们采用pipline进行构建)

a.  配置获取最新提交信息:在checkout 步骤 新增  

 

 

      script {
        env.commit = "${sh(script:'git log --oneline --no-merges|head -1', returnStdout: true)}"
      }

b. 在 post步骤添加触发命令

 

 

      wrap([$class: 'BuildUser']) {
        sh """curl 'https://oapi.dingtalk.com/robot/send?access_token=5d0dc954f00b717ab3cc44ff2a3eb41da355eb57aa73xxxxxx'  -H 'Content-Type: application/json' -d '{"msgtype":"text","text":{"content": "部署服务:${JOB_NAME} \n构建分支: ${branch}\n构建ID: ${BUILD_ID}\n构建人: ${BUILD_USER}\n提交信息:${commit}构建状态:${currentBuild.currentResult}"}}'"""
      }

配置完构建测试。

posted @ 2020-07-21 16:34  imcati  阅读(2166)  评论(0编辑  收藏  举报