python -- Jenkins에서 설정한 작업을 Excel로 내보내기

9949 단어
jenkins 작업 모두 Excel, 전체 코드로 내보내기
from jenkins import Jenkins
import xlwt,re

jen = Jenkins(url="jenkins ", username=" ", password=" ")
all_jobs = jen.get_all_jobs()

def export_excel():
    wb = xlwt.Workbook(encoding='utf-8')
    ws = wb.add_sheet('test')
    style = xlwt.XFStyle()
    #  
    font = xlwt.Font()
    style.font = font
    #  
    alignment = xlwt.Alignment()
    #  
    alignment.horz = xlwt.Alignment.HORZ_CENTER
    alignment.vert = xlwt.Alignment.VERT_CENTER
    #  
    alignment.wrap = 1
    style.alignment = alignment
    ws.write(0, 0, '_class')
    ws.write(0, 1, 'name')
    ws.write(0, 2, 'url')
    ws.write(0, 3, 'color')
    ws.write(0, 4, 'fullname')
    ws.write(0, 5, 'gitUrl')
    ws.write(0, 6, 'shell')
    try:
        for i in range(len(all_jobs)):
            ws.write(i+1,0,all_jobs[i].get('_class'))
            ws.write(i+1,1,all_jobs[i].get('name'))
            ws.write(i+1,2,all_jobs[i].get('url'))
            ws.write(i+1,3,all_jobs[i].get('color'))
            ws.write(i+1,4,all_jobs[i].get('fullname'))
            print(all_jobs[i].get('name'))
            name_list = ['compile',               # name_list git shell 'knowledge',
                         'database',
                         'docker-images','python-runtime-build']
            if all_jobs[i].get('name') in name_list:
                pass
            else:
                conf = jen.get_job_config(name=all_jobs[i].get('name'))
                url = re.finditer(r".*?", conf)
                for match in url:
                    gitUrl = match.group()
                    ws.write(i+1, 5, gitUrl.lstrip('').rstrip(''))
                comm = re.finditer(r"[\s\S]*?", conf)
                for match in comm:
                    shellComm = match.group()
                    shellStr = shellComm.lstrip('').rstrip('')   #  
                    shellstr = re.sub(r'"', '"', shellStr)        #  
                    shellstr = re.sub(r''',"'",shellstr)          #  
            shellstr = re.sub(r'&',"&",shellstr)       # &
ws.write(i + 1, 6, shellstr) except Exception as e: print(e) # excel wb.save('./test.xls') if __name__ == '__main__': export_excel()

좋은 웹페이지 즐겨찾기