jenkins 接入ding ding 发消息

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

python 代码json

#!/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} 已经编译好,存放路径:\\\\*\\*\*\\*\\alpha\\{1}\\{0}'.format(cand_num,rom_version),1,181******)
#!/usr/bin/env python2
#coding=utf-8
# -*- coding: utf-8 -*-
import json,urllib2,time,os,sys
car_type=os.getenv('car_type')
rom_path=os.getenv('PATH').replace('/','\\')
StageIdentification=os.getenv('StageIdentification')
print car_type
DingTalkToken=["https://oapi.dingtalk.com/robot/send?access_token=*******"]

def Dintalk(cand,result,phone,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(token,jd)
	req.add_header('Content-Type', 'application/json')
	response=urllib2.urlopen(req)

if StageIdentification == "Alpha" or StageIdentification == "Release":
  	for token in DingTalkToken:
		Dintalk('{0} {2} ****:\\\\***\\***\\****\\{1}'.format(car_type,rom_path,StageIdentification),1,1812222,token)
相关文章
相关标签/搜索