【Python】從Jenkins下載最近一次成功構建的安裝包
#-*- coding:utf-8 -*-
from case.beatles.test_beatles import TestBeatles
from framework.logger import Logger
from page.ios.beatles.jenkins_page import Jenkins_Tool
class DownloadApp(TestBeatles):
def testDownloadfromJenkins(self):
try:
jp = Jenkins_Tool()
jp.download_app_from_jenkins()
except Exception, e:
Logger.error(e)
self.save_screenshot()
self.fail(e.message)
#-*- coding:utf-8 -*-
from datetime import datetime
import urllib
import jenkins
import os
job_names = [`job-ios`,`job_android`]
username = `Jenkins使用者名稱`
password = `Jenkins密碼`
base_ios_debug_download_url = `https://xxx/ios/Debug/`
base_android_debug_download_url = `https://xxx/android/Debug/`
ios_app_suffix = `.ipa`
class Jenkins_Tool():
def __init__(self):
self.jenkins_url = `http://jenkins host url`
self.sever = jenkins.Jenkins(self.jenkins_url, username=username, password=password)
# 獲取最新構建號
def get_build_number(self, job_name):
lastest_completed_build_number = self.sever.get_job_info(job_name)[`lastCompletedBuild`][`number`]
# print(lastest_completed_build_number)
return lastest_completed_build_number
# 獲取Jenkins下的所有job
def get_all_jobs(self):
all_josbs = self.sever.get_all_jobs()
print(self.sever.jobs_count())
for job in all_josbs:
print(job[`name`])
# 獲取構建日誌
def get_build_console_output(self, job_name):
number = self.get_build_number(job_name)
resps = (self.sever.get_build_console_output(job_name, number))
print(resps)
# 生成ios下載的絕對URL
def getIosAbsoluteURL(self, job_name):
ios_download_url = base_ios_debug_download_url + str(self.get_build_number(job_name)) + `/` + self.getPkgName(job_name)
return ios_download_url
# 生成android下載的絕對URL
def getAndroidAbsoluteURL(self, job_name):
android_download_url = base_android_debug_download_url + str(self.get_build_number(job_name)) + `/` + self.getPkgName(job_name)
return android_download_url
# 拼接包名
def getPkgName(self, job_name):
number = self.get_build_number(job_name)
if job_name == `carpool_iosbuild`:
pkg_name = `iOS包名字首` + str(number) + `_.ipa`
# print(pkg_name)
return pkg_name
else:
pkg_name = `Android包名.apk`
return pkg_name
# 從Jenkins下載最新ios App
def download_ios_app(self, job_name):
local = os.path.join(`/Users/didi/Downloads/`, self.getPkgName(job_name))
ios_download_url = self.getIosAbsoluteURL(job_name)
print(`開始下載iOS App...`)
urllib.urlretrieve(ios_download_url, local)
print(`iOS App 下載完成`)
# 從Jenkins下載最新android App
def download_android_app(self, job_name):
local = os.path.join(`/Users/didi/Downloads/`, self.getPkgName(job_name))
android_download_url = self.getAndroidAbsoluteURL(job_name)
print(`開始下載Android App...`)
urllib.urlretrieve(android_download_url, local)
print(`Android App 下載完成`)
# 下載進度
def callbackfunc(blocknum, blocksize, totalsize):
```回撥函式
@blocknum: 已經下載的資料塊
@blocksize: 資料塊的大小
@totalsize: 遠端檔案的大小
```
percent = 100.0 * blocknum * blocksize / totalsize
if percent > 100:
percent = 100
print "%.2f%%" % percent
# 重新命名ios app
def rename(self, file_dir, file_name):
os.chdir(file_dir) #切換目錄
# print "當前目錄為: %s" % os.listdir(os.getcwd())
for root, dirs, files in os.walk(file_dir):
os.listdir(os.getcwd()) # 獲得當前目錄中的內容
for file in files:
if os.path.splitext(file)[1] == `.ipa`:
os.rename(file_name, `xxx`+ios_app_suffix)
print(`ios app已重新命名為 xxx.ipa`)
return
#從Jenkins下載最新的構建包
def download_app_from_jenkins(self):
jt = Jenkins_Tool()
start_download_time = datetime.now() # 開始下載時間
jt.download_ios_app(`ios-job`)
jt.rename(`/Users/didi/Downloads/`,jt.getPkgName(`ios-job`))
jt.download_android_app(`android-job`)
end_download_time = datetime.now() # 下載完成時間
print(`Android & iOS下載耗時:` + str((end_download_time - start_download_time).seconds))
return True
相關文章
- 下載Python安裝包及支援包路徑Python
- python 使用pip安裝使用國內映象加速下載安裝包的方法Python
- 為 OpenWrt 構建 ipk 安裝包
- python原始碼包怎麼下載?方便安裝嗎?Python原始碼
- postgresql下載安裝包如何解壓安裝SQL
- Python Selenium安裝下載Python
- ElasticSearch 7.6.2 下載包 及 安裝Elasticsearch
- Hadoop一鍵下載安裝包Hadoop
- 如何下載安裝壓縮包
- Python 下載安裝和配置Python
- rhel9.2離線下載安裝包,並安裝
- 安裝Python下載的是asc格式?Python
- docker下安裝部署jenkins(一)DockerJenkins
- Project Office X 中文下載Mac安裝包ProjectMac
- python的下載安裝與簡單使用Python
- (原創)下載安裝Python第三方包庫pip安裝失敗總結Python
- Linux下怎麼安裝.deb格式的安裝包?Linux系統下.deb格式安裝包的安裝教程Linux
- 快速安裝python包Python
- python下載包(pycharm)PythonPyCharm
- Centos7.6下安裝配置JenkinsCentOSJenkins
- Yum命令之僅下載rpm安裝包且不安裝
- pip和conda下載包到本地並安裝
- 谷歌瀏覽器下載離線安裝包谷歌瀏覽器
- 軟體下載卻安裝不成功如何解決
- Jenkins安裝Jenkins
- typora下載安裝以及notepad++下載安裝
- 剛剛下載一個最新的包,安裝有問題
- 清除python下載的錯誤包Python
- python 包安裝筆記Python筆記
- 軟體下載卻安裝不成功是如何解決
- 怎麼看python是否安裝成功Python
- Jenkins定時構建Jenkins
- Jenkins 構建 Exec timeout!Jenkins
- windows系統下python下載與安裝以及視覺化工具PyCharm安裝WindowsPython視覺化PyCharm
- docker 安裝最新的 jenkinsDockerJenkins
- 安裝python下的 you-get 超級媒體下載器Python
- ubuntu 安裝jenkinsUbuntuJenkins
- yum 安裝 jenkinsJenkins