import jenkins
class mbuild:
def __init__(self, url):
self.__url=url
self.__server=jenkins.Jenkins(self.__url, 15)
def last_build_version(self, projectName):
jobj=self.__server.get_all_jobs()
for job in jobj:
if(job['fullname']==projectName):
info= self.__server.get_job_info(projectName)
return info['lastSuccessfulBuild']['number']
return None
def get_build_file_url(self, projectName, buildNumber, fileNameRegi):
files=[]
buildinfo = self.__server.get_build_info(projectName, buildNumber)
buildurl=self.__server.get_job_info(projectName)['lastSuccessfulBuild']['url']
for artifact in buildinfo['artifacts']:
if(fileNameRegi in artifact['fileName']):
files.append(buildurl + 'artifact/'+ artifact['relativePath'])
return files
def download_build(self, fileURLs, testFolder):
files=[]
for fileURL in fileURLs:
filenames=fileURL.split('/')
if(len(filenames)>0):
filename=filenames[len(filenames)-1]
fileContent=requests.get(fileURL)
with open(testFolder + '/' + filename, 'wb') as content:
content.write(fileContent.content)
files.append(testFolder + '/' + filename)
return files