|
@@ -1,3 +1,4 @@
|
|
|
+import os
|
|
|
import socket
|
|
|
from pathlib import Path
|
|
|
from dingtalkchatbot.chatbot import DingtalkChatbot
|
|
@@ -9,23 +10,23 @@ import jenkins # 安装pip install python-jenkins
|
|
|
# s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
# s.connect(("8.8.8.8", 80))
|
|
|
# ip = s.getsockname()[0]
|
|
|
-# # jenkins登录地址
|
|
|
-# jenkins_url = "http://" + f"{ip}" + ":8080"
|
|
|
-# # 获取jenkins对象
|
|
|
-# server = jenkins.Jenkins(jenkins_url, username='admin', password='9d9768cf3aac4ae38aa18f2797246cde') # Jenkins登录名 ,密码
|
|
|
-#
|
|
|
-# # job名称
|
|
|
-# job_name = "job/ui_frame/" # Jenkins运行任务名称
|
|
|
-# # job的url地址
|
|
|
-# job_url = jenkins_url + job_name
|
|
|
-# # 获取最后一次构建
|
|
|
-# job_last_build_url = server.get_info(job_name)['lastBuild']['url']
|
|
|
-# # 报告地址
|
|
|
-# report_url = job_last_build_url + 'allure' # 'allure'为我的Jenkins全局工具配置中allure别名
|
|
|
-# if "localhost" in report_url:
|
|
|
-# report_url = report_url.replace("localhost", ip)
|
|
|
-# else:
|
|
|
-# report_url = report_url
|
|
|
+# jenkins登录地址
|
|
|
+jenkins_url = "http://121.229.175.82:63222/"
|
|
|
+# 获取jenkins对象
|
|
|
+server = jenkins.Jenkins(jenkins_url, username='jiangwei', password='jW@123456') # Jenkins登录名 ,密码
|
|
|
+
|
|
|
+# job名称
|
|
|
+job_name = "job/qccq/" # Jenkins运行任务名称
|
|
|
+# job的url地址
|
|
|
+job_url = jenkins_url + job_name
|
|
|
+# 获取最后一次构建
|
|
|
+job_last_build_url = server.get_info(job_name)['lastBuild']['url']
|
|
|
+# 报告地址
|
|
|
+report_url = job_last_build_url + 'allure' # 'allure'为我的Jenkins全局工具配置中allure别名
|
|
|
+if "localhost" in report_url:
|
|
|
+ report_url = report_url.replace("localhost", ip)
|
|
|
+else:
|
|
|
+ report_url = report_url
|
|
|
'''
|
|
|
钉钉推送方法:
|
|
|
读取report文件中"prometheusData.txt",循环遍历获取需要的值。
|
|
@@ -37,10 +38,11 @@ def DingTalkSend(info):
|
|
|
d = {}
|
|
|
# 获取项目绝对路径
|
|
|
path = Path(__file__).parent
|
|
|
- file = r"\report\export\prometheusData.txt"
|
|
|
+ file = '/report/export/prometheusData.txt'
|
|
|
print(rf"{path}" + rf"{file}")
|
|
|
# 打开prometheusData 获取需要发送的信息
|
|
|
- f = open(rf"{path}" + rf"{file}", 'r', encoding='UTF-8')
|
|
|
+ # f = open(rf"{path}" + rf"{file}", 'r', encoding='UTF-8')
|
|
|
+ f =open(os.getcwd()+file,'r', encoding='UTF-8')
|
|
|
for lines in f:
|
|
|
for c in lines:
|
|
|
launch_name = lines.strip('\n').split(' ')[0]
|
|
@@ -63,22 +65,22 @@ def DingTalkSend(info):
|
|
|
|
|
|
# 钉钉推送
|
|
|
|
|
|
- url = 'https://oapi.dingtalk.com/robot/send?access_token=a390afae52f08c29e0c59b8ceda9ed57b573a0839461ab3a0325e2332099d4e2' # webhook
|
|
|
+ url = 'https://oapi.dingtalk.com/robot/send?access_token=00fd89864b0527c2fd401ac470d0bd89e43de2ce5523fd3aeab44c85671e5d8e' # webhook
|
|
|
text = (
|
|
|
- f"<font color=\'#FFA500\'>[通知] </font>投资建设-{info}测试报告"
|
|
|
+ f"<font color=\'#FFA500\'>[通知] </font>青春重庆-{info}测试报告"
|
|
|
"\n\n用例运行总数: " + retries_run +
|
|
|
"\n\n用例未执行数: " + status_defects +
|
|
|
"\n\n用例通过数量: " + status_passed +
|
|
|
'''\n\n<font>用例失败数量: </font><font color=\'#FF0000\' size=2>%s</font> \n\n''' +
|
|
|
# "\n\n构建地址:\n" + job_url +
|
|
|
- # "\n\n测试报告地址: \n" + report_url +
|
|
|
+ "\n\n测试报告地址: \n" + report_url +
|
|
|
"\n\n播报时间: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) % (status_failed)
|
|
|
|
|
|
dd_robot = DingtalkChatbot(url)
|
|
|
|
|
|
- ret = dd_robot.send_markdown(title='投资建设', text=text, is_at_all=True, )
|
|
|
+ ret = dd_robot.send_markdown(title='青春重庆', text=text, is_at_all=False)
|
|
|
print(ret)
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- DingTalkSend()
|
|
|
+ DingTalkSend("生产")
|