使用Jenkins 接入 ding ding 给 钉钉群发消息

python 代码

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import json,urllib2,time,os,sys
cand_num=os.getenv('cand') #使用os.getenv 获取Jenkins 参数
rom_version=os.getenv('rom_version')+"."+os.getenv('rom_version_x')
def Dintalk(cand,result,phone):
	url='https://oapi.dingtalk.com/robot/send?access_token=**********'
	if result ==1:
		con={"msgtype":"text","text":{"content":cand+"\n"},
		"at":{"atMobiles":phone,"isAtAll":"false"}}
	else:
		con={"msgtype":"text","text":{"content":cand+"\n"},
		"at":{"atMobiles":phone,"isAtAll":"true"}}
	jd=json.dumps(con)
	req=urllib2.Request(url,jd)
	req.add_header('Content-Type', 'application/json')
	response=urllib2.urlopen(req)
Dintalk('{0} 已经编译好,存放路径:\\\\192.168.0.188\\android\data\\binary\\alpha\\{1}\\{0}'.format(cand_num,rom_version),1,181******)
11-30 23:21