python-jenkins API获取指定视图项目写入excel

import jenkins
import datetime
import xlwt

 


now = datetime.datetime.now()
zeroToday = now - datetime.timedelta(hours=now.hour, minutes=now.minute, seconds=now.second,
                                         microseconds=now.microsecond)
yestday = zeroToday - datetime.timedelta(seconds=1)

server = jenkins.Jenkins('http://192.168.10.1:8080', username='name', password='passwd')
all_jobs_li = server.get_all_jobs()
count = 0
book = xlwt.Workbook()
sheet = book.add_sheet('jobname')
sheet.write(0, 0, 'jobname')
sheet.write(0, 1, 'projectname')
sheet.write(0, 2, 'codepath')
sheet.write(0, 3, '负责人')
for item in all_jobs_li:

        a = item['name']
        if a.startswith('Timer'):
                count += 1
                last_build_number = server.get_job_info(item['name'])['lastCompletedBuild']['number']
                build_info = server.get_build_info(item['name'], last_build_number)
                sss = build_info['timestamp']

                result = build_info['result']
                buildNumber = build_info['number']
                # print(build_info['number'])
                dateArray = datetime.datetime.utcfromtimestamp(float(sss) / 1000) + datetime.timedelta(hours=8)

                eob = server.get_build_info(item['name'], build_info['number'])
                    # for i in eob:
                    #   print(i)
                jobname = item['name']
                print(jobname)
                yyy= eob['actions']
                # print(jobname)
                ls2 = ['causes']
                ls4 =['parameters']
                ls3=[]
                ls5 = []

                for i in yyy:
                      if ls2[0] in i:
                        ls3.append(i)
                        tttt=ls3[0]
                        ggg=tttt['causes']

                        jjjj=ggg[0]
                        builduser = jjjj['shortDescription']
                        # queryset = Jrate.objects.all().filter(pub_date__range=(start_date, end_date))

                for param in yyy:
                        if ls4[0] in param:
                            ls5.append(param)
                            rrrr = ls5[0]

                            kkk =rrrr['parameters']

                arr = []

                for itm in kkk:
                        # print(itm['name'])

                        arr.append(itm['name'])

                        if itm['name'] == 'projectname':
                            # print(itm['value'])
                          pname =itm['value']
                          # print(pname)
                        if itm['name'] == 'code_path':
                          cname =itm['value']
                          # print(cname)

 

                if "code_path" in arr:
                    cname = cname
                else:
                    cname = "kong"

                print(count)
                # print(jobname + ":" + pname + ":" + cname)

 


                sheet.write(count,0, jobname)
                sheet.write(count, 1, pname)
                sheet.write(count, 2, cname)
book.save('TimerInfo.xls')

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值