【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
- 為 OpenWrt 構建 ipk 安裝包
- python 使用pip安裝使用國內映象加速下載安裝包的方法Python
- postgresql下載安裝包如何解壓安裝SQL
- python原始碼包怎麼下載?方便安裝嗎?Python原始碼
- ElasticSearch 7.6.2 下載包 及 安裝Elasticsearch
- 如何下載安裝壓縮包
- centos下安裝jenkinsCentOSJenkins
- Hadoop一鍵下載安裝包Hadoop
- rhel9.2離線下載安裝包,並安裝
- homebrew下載安裝及mysql的下載安裝MySql
- Project Office X 中文下載Mac安裝包ProjectMac
- Python 下載安裝和配置Python
- Python Selenium安裝下載Python
- 安裝Python下載的是asc格式?Python
- docker下安裝部署jenkins(一)DockerJenkins
- 軟體包無法下載情況下安裝nfsNFS
- 谷歌瀏覽器下載離線安裝包谷歌瀏覽器
- oracle_sqldev64_jdk 下載安裝JDK 包OracleSQLdevJDK
- Jenkins 從零開始-安裝(一)Jenkins
- (原創)下載安裝Python第三方包庫pip安裝失敗總結Python
- python的下載安裝與簡單使用Python
- 軟體下載卻安裝不成功如何解決
- python下載包(pycharm)PythonPyCharm
- Linux下怎麼安裝.deb格式的安裝包?Linux系統下.deb格式安裝包的安裝教程Linux
- Yum命令之僅下載rpm安裝包且不安裝
- 剛剛下載一個最新的包,安裝有問題
- Centos7.6下安裝配置JenkinsCentOSJenkins
- 快速安裝python包Python
- 安裝Python requests包Python
- 軟體下載卻安裝不成功是如何解決
- Windows下安裝Python、matplotlib包 及相關WindowsPython
- Linux下的oracle終於安裝成功LinuxOracle
- VMware安裝VMware tool後mount /dev/cdrom /mnt成功掛載含rpm包的映象dev
- Jenkins安裝Jenkins
- 如何下載谷歌瀏覽器.crx外掛安裝包谷歌瀏覽器
- NTFS Disk by Omi NTFS 1.1.4啟用版下載安裝包
- typora下載安裝以及notepad++下載安裝