Jenkins運行成功後,須要發送消息給用戶,本身封裝了一個rtx的方法,進行發送,配置方法以下:html
1.在windows下選擇 execute windows batch command,執行個人python文件,python
注意,在liunx系統中要使用 execute shellshell
自定義的消息內容爲:json
個人消息內容讀取的是生成文件的html,windows
代碼以下:api
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author: User # @Date : 2019/3/15 10:42 # @Desc : Description import requests,json from bs4 import BeautifulSoup class message: def __init__(self,url): self.url=url def MyHTMLParser(self): executeStae= "成功" result = [] #打開文件 soup = BeautifulSoup(open(self.url)) #獲取執行時間 runTime = soup.td.string # 過濾主要的數據 htmlContnet=soup.find_all(align='center',limit=1) print(htmlContnet) #單個同級的目錄的數據 sumNumber=htmlContnet[0].td.next_sibling.string #同級目錄的數據 for siblings in htmlContnet[0].td.next_siblings: sigle=siblings.string print(siblings) result.append(sigle) faileNmuber=result[0] successNmuber=int(sumNumber)-int(result[0]) if faileNmuber!=0: executeStae="失敗" content = '運行信息:\r\n總接口數:' + str(sumNumber) + \ ', 經過:' + str(successNmuber) + \ ', 未經過:' + str(faileNmuber) + \ '\r\n運行結果:' + executeStae + \ '\r\n運行時間:' + runTime return content def sendsRtx(self,contnet): url = 'http://msgcenter100.com/api-source/index' payload = { "account": "xx", "password": "xx", "api_key": "xx", "data": [ { "content": xx, "title": "TEST", "to": "xx", "channel": "rtx" } ] } res = requests.post(url, data=json.dumps(payload)) print(res.text) if __name__=='__main__': m=message('D:/jmeterDemo/demo/report/html/23$.html') transForm=m.MyHTMLParser() m.sendsRtx(transForm)