Now the mobile side of the development of many teams have used the Jenkins+gradle Android code to the APK, but how to the apk to our mobile phone, then we will think of QR code scanning to do such a simple thing:
1, to know the Jenkins project
2. Know where Jenkins's tool space and package are stored
3, to use Python to generate two-dimensional code images
4, in order to put the picture in HTTP can be directly accessed.
I only have the simple code, the other can be changed according to the actual situation, such as how to get the latest apk from the file name, but also from the Urllib from the page to get the latest apk and so on
Configuration file:
[Config] # Jenkins address jenkins_address = http://192.168.1.82:8080#Jenkins in the project name project_name = ProjectName#Jenkins working space jenkins_space = C:\Users\Administrator\.jenkins# Project Package storage location Apk_home = build_apk
Run code: Prompt this is under window, in fact, Linux will be better, because to use the timer, Linux direct crontab is good.
1 #-*-coding=utf-8-*-2 ImportQRCode3 Import Time4 ImportOS5 ImportConfigparser6 #get the latest built packets7 classqr_config ():8 def __init__(self):9SELF.CF =Configparser.configparser ()TenSelf.cf.read ("Config.ini") OneSelf.jenkins_pro_address = Self.cf.get ("Config","jenkins_address") ASelf.project_name = Self.cf.get ("Config","Project_Name") -Self.apk_home = Self.cf.get ("Config","Apk_home") -Self.jenkins_space = Self.cf.get ("Config","Jenkins_space") theSelf.today_time = Time.strftime ("%y-%m-%d") - - defGet_apk_url (self): - +Today_dir ="%s\\jobs\\%s\\workspace\\%s\\%s"%(Self.jenkins_space, - Self.project_name, + Self.apk_home, A self.today_time) at ifos.path.exists (today_dir): -File_list =Os.listdir (Today_dir) -file_name = file_list[-1] - iffile_name: -Down_url ="%s/job/%s/ws/%s/%s/%s"%(self.jenkins_pro_address, - Self.project_name, in Self.apk_home, - Self.today_time, to file_name) + returnDown_url - Else: the Print "file does not exist, today build failed! " * Else: $ Print "There is no build today! "Panax Notoginseng - if __name__=="__main__": thelink =qr_config (). Get_apk_url () +PNG ="C:\Users\\Administrator\\Desktop\\1.3.2top.png" Aqr = QRCode. QRCode (version=1, theerror_correction=Qrcode.constants.ERROR_CORRECT_L, +Box_size=8, -Border=8,) $ qr.add_data (link) $Qr.make (fit=True) -IMG =qr.make_image () -Img.save ("Android_qr_code.png","')
Don't forget to move the picture to a directory that HTTP can access.
Download a QR code to download the APK from Jenkins built with Python