使用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)