Python+jenkins自动化打包脚本(自动打包+下载+存储到本地)
一、需求描述
企业使用jenkins工具打包,每次都要去jenkins点击构建,构建完成后还要去手动下载保存,为了方便可以直接写个一体化脚本实现打动+下载+保存。
二、代码如下
import sys sys.path.append("/Users/xxx/Documents/python/pack") from jenkins import get_packagename import time from apk_download import download from get_build_number import get_BuildNumber from lxml import html from pack_interface import pack_inter def pack(pack_name): # 请求jenkins构建接口 pack_inter(pack_name) print('开始打包...') time.sleep(1) # 访问jenkins首页判断是否还在构建中 home_url = 'http://xx.xx.xx/' cookie = 'xxx' time.sleep(480) while True: package_name_list = get_packagename(home_url,cookie) if pack_name in package_name_list: pass else: print('打包完成...') break time.sleep(5) # 获取jenkins构建号,后面用于传入下载接口进行下载 build_number = get_BuildNumber(pack_name) # 下载app download(pack_name,build_number) if __name__ == '__main__': pack_name = input('请输入打包名称(Prod/Test):') pack(pack_name)