python package 之 jenkins

    最近打算写一下自动化结果(UT和AT)的DashBoard(显示一下微服务一段时间的结果),所以需要写个小脚本来做一些事情。

    首先要得到jenkins job中的console 的结果,我使用的是通过jenkins的api进行得到结果:

    如何得到API Token:  在Jenkins登录后右上角账户 --》 设置  --》点击 show API Token

   

 

  1. 得到job最新的build number
  2. 得到对应job的console log,然后进行正则表达式得到对应job的UT & AT的行覆盖率和类覆盖率
# coding:utf-8

import jenkins
import re

job_names = ['store/store-outer/store-openapi-build',
            'store/store-outer/store-openapi-zbrd-auto']

username = 'xxxx'
password = '0e10e619c76a35513ec5a4bfe2b0d5c4'


class Jenkins_Tool():

    def __init__(self):
        self.jenkins_url = 'http://jenkins.xxxx.com/jenkins/'
        self.sever = jenkins.Jenkins(self.jenkins_url, username=username, password=password)

    def get_build_number(self, job_name):
        return (self.sever.get_job_info(job_name)['lastCompletedBuild']['number'])

    def get_build_console_output(self, job_name):
        number = self.get_build_number(job_name)
        line_coverage = 0
        code_coverage = 0
        resps= (self.sever.get_build_console_output(job_name, number))
        line_code = (re.search(r'(line:)\s(\d+)', resps, re.M))
        class_code = (re.search(r'(class:)\s(\d+)', resps, re.M))
        if line_code and class_code:
            line_coverage = line_code.group(2)
            code_coverage = class_code.group(2)
	print "行覆盖率为:{0}".format(line_coverage)
	print "类覆盖率为:{0}".format(code_coverage)


test = Jenkins_Tool()
for job_name in job_names:
    test.get_build_console_output(job_name)

时间比较紧,所以就写了点点,不过可以通过上面的代码得到对应jenkins job的console log了,然后通过正则得到想要得到的值,以后再进行优化吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值