本文整理汇总了Python中jenkins.Jenkins.build_job方法的典型用法代码示例。如果您正苦于以下问题:Python Jenkins.build_job方法的具体用法?Python Jenkins.build_job怎么用?Python Jenkins.build_job使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jenkins.Jenkins
的用法示例。
在下文中一共展示了Jenkins.build_job方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
class JobBuilder:
def __init__(self, jenkinsURL):
self.j = Jenkins(jenkinsURL)
self.jobName = ""
def add_job(self, jobName, configString):
self.jobName = jobName
if self.j.job_exists(jobName):
#Job exist in the job list
return False
else:
self.j.create_job(self.jobName, configString)
self.j.enable_job(self.jobName)
return True
def run_job(self, **params):
if self.jobName == "":
print "Have to add job firstly"
return False
else:
self.j.enable_job(self.jobName)
self.j.build_job(self.jobName, params)
示例2: build_jobs
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def build_jobs(credentials, test_plans, args):
jenkins = Jenkins('http://juju-ci.vapour.ws:8080', *credentials)
for test_plan in test_plans:
test_id = generate_test_id()
for controller in args.controllers:
job_name = get_job_name(controller)
parameter = make_parameters(test_plan, args, controller, test_id)
jenkins.build_job(job_name, parameter, token=args.cwr_test_token)
示例3: reportUsingJenkinsEmailPlugin
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def reportUsingJenkinsEmailPlugin(self, marvinConfigJson, env, execOnOneZone = True):
try:
jobIdentifierList = []
bugLoggerData = []
j = Jenkins('http://jenkins-ccp.citrix.com', 'bharatk', 'BharatK')
for zone in cscfg.zones:
self.logger.info(zone.name)
for pod in zone.pods:
for cluster in pod.clusters:
self.logger.info('creating a jeknins job to generate results and email notfication for hypervisor %s and zone %s' % (cluster.hypervisor, zone.name))
modifiedjob = jobModifier.modifyReportGenerator(env['build_number'] + '_' + zone.name + '_' + cluster.hypervisor, mailto)
jobname = modifiedjob
file = open('/root/cloud-autodeploy2/newcode/' + modifiedjob, 'r')
config = file.read()
file.close()
j.create_job(modifiedjob, config)
j.build_job(modifiedjob, {'buildNumber': env['build_number'],
'BuildNo': env['build_number'],
'MGMT_SVR': env['hostip'],
'BASEDIR': env['virtenvPath'],
'version': env['version'],
'BranchInfo': env['version'],
'GitRepoUrl': env['repo_url'],
'GitCommitId': env['commit_id'],
'CIRunStartDateTime': env['startTime'],
'CIRunEndDateTime': time.strftime('%c'),
'WikiLinks': 'https://cwiki.apache.org/confluence/display/CLOUDSTACK/Infrastructure%2CCI%2CSimulator%2CAutomation+Changes',
'hypervisor': cluster.hypervisor.lower(),
'HyperVisorInfo': cluster.hypervisor.lower(),
'zoneName': zone.name,
'BuildReport': 'https://www.dropbox.com/sh/yj3wnzbceo9uef2/AAB6u-Iap-xztdm6jHX9SjPja?dl=0',
'token': 'bharat'})
jobIdentifierList.append('report_' + zone.name)
jobDetails = {'job_name': modifiedjob,
'related_data_path': env['virtenvPath']}
self.resourceMgr.addJobDetails(jobDetails)
bugLoggerData.append({'hypervisor': cluster.hypervisor.lower(),
'branch': env['version'],
'logname': cluster.hypervisor.lower() + '__Log_' + env['build_number'],
'type': 'BVT'})
self.logger.info('bug logger data in zone looop %s' % bugLoggerData)
self.waitForJobComplete(env['virtenvPath'], jobIdentifierList)
self.archiveTestRunLogs(env, cluster.hypervisor.lower(), jobname)
break
break
if execOnOneZone:
break
self.logger.info('job identifier list %s' % jobIdentifierList)
self.logger.info('cleaning up the workspace')
bash('rm -f /root/cloud-autodeploy2/newcode/%s' % modifiedjob)
self.logger.info('running bug logger')
except Exception as e:
self.logger.exception(e)
示例4: build_job
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def build_job(credentials, root, job_name, candidates, suite):
parameters = {'suite': ','.join(suite), 'attempts': '10'}
jenkins = Jenkins('http://juju-ci.vapour.ws:8080', credentials.user,
credentials.password)
for candidate, revision_build in candidates:
call_parameters = {
'revision_build': '{:d}'.format(revision_build),
}
call_parameters.update(parameters)
jenkins.build_job(job_name, call_parameters)
示例5: build_jobs
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def build_jobs(credentials, test_plans, args):
jenkins = Jenkins('http://juju-ci.vapour.ws:8080', *credentials)
for test_plan in test_plans:
test_id = generate_test_id()
test_plan_content = load_test_plan(test_plan)
test_label = test_plan_content.get('test_label')
if test_label and isinstance(test_label, str):
test_label = [test_label]
for controller in test_label or args.controllers:
job_name = get_job_name(controller)
parameter = make_parameters(test_plan, controller, test_id)
jenkins.build_job(job_name, parameter, token=args.cwr_test_token)
示例6: __init__
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
class TaskBuilder:
def __init__(self, jenkinsURL):
self.j = Jenkins(jenkinsURL)
self.jobName = ""
with open("config.xml") as file:
self.templateConfig = file.read()
self.template = Template(unicode(self.templateConfig))
def set_new_config(self, **params):
self.newConfig = self.template.render(repos=params['repos'], description=params['repos'])
def add_build(self, **params):
self.set_job_name(**params)
self.set_new_config(**params)
if self.j.job_exists(self.jobName):
self.do_build(**params)
else:
self.j.create_job(self.jobName, self.newConfig)
self.do_build(**params)
def do_build(self, **params):
self.set_job_name(**params)
self.set_new_config(**params)
self.j.enable_job(self.jobName)
self.j.build_job(self.jobName, {'branch': params['branch'], 'version': params['version'], 'package_list': params['package_list']})
def set_job_name(self,**params):
buildUtil = BuildUtil()
self.jobName = buildUtil.get_job_name(repos=params['repos'])
def get_build_status(self, **params):
#job_info = self.j.get_job_info(self.jobName)
#return build_status
pass
def get_job_name(self):
return self.jobName
示例7: JenkinsBot
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
#.........这里部分代码省略.........
@botcmd(split_args_with=None)
def jenkins_param(self, mess, args):
"""List Parameters for a given job."""
if len(args) == 0:
return 'What Job would you like the parameters for?'
self.connect_to_jenkins()
job = self.jenkins.get_job_info(args[0])
if job['actions'][1] != {}:
job_param = job['actions'][1]['parameterDefinitions']
elif job['actions'][0] != {}:
job_param = job['actions'][0]['parameterDefinitions']
else:
job_param = []
return self.format_params(job_param)
@botcmd(split_args_with=None)
def jenkins_build(self, mess, args):
"""Build a Jenkins Job with the given parameters
Example: !jenkins build test_project FOO:bar
"""
if len(args) == 0: # No Job name
return 'What job would you like to build?'
self.connect_to_jenkins()
params = self.build_parameters(args[1:])
# Is it a parameterized job ?
job = self.jenkins.get_job_info(args[0])
if job['actions'][0] == {} and job['actions'][1] == {}:
self.jenkins.build_job(args[0])
else:
self.jenkins.build_job(args[0], params)
running_job = self.search_job(args[0])
return 'Your job should begin shortly: {0}'.format(
self.format_jobs(running_job))
@botcmd(split_args_with=None)
def build(self, mess, args):
"""Shortcut for jenkins_build"""
return self.jenkins_build(mess, args)
@botcmd
def jenkins_unqueue(self, msg, args):
"""Cancel a queued job.
Example !jenkins unqueue foo
"""
self.connect_to_jenkins()
try:
queue = self.jenkins.get_queue_info()
job = next((job for job in queue if job['task']['name'].lower() == args.lower()), None)
if job:
self.jenkins.cancel_queue(job['id'])
return 'Unqueued job {0}'.format(job['task']['name'])
else:
return 'Could not find job {0}, but found the following: {1}'.format(
args, ', '.join(job['task']['name'] for job in queue))
except JenkinsException as e:
return 'Oops, {0}'.format(e)
示例8: execOnJenkins
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def execOnJenkins(self, env, testSpecifierString, mailto, reRunFailedTests=True, retryCount=1, report=True, execOnOneZone=True,
postOnPr=False, testMgr=None, avoidZones=None):
try:
env['hypervisor'] = ''
if avoidZones is None:
avoidZones=[]
if testMgr is None:
testMgr = testManager(testSpecifierString, env['virtenvPath'])
jobModifier = modifyJOb()
modifiedjob = ''
j = Jenkins('http://jenkins-ccp.citrix.com', 'bharatk', 'BharatK')
tests = testMgr.getTests()
if tests == None:
raise Exception('found no tests to run')
while tests is not None:
os.chdir(env['virtenvPath'])
self.logger.info('launching jenkins TestExecutor Job')
cscfg = configGenerator.getSetupConfig(env['config_file'])
for zone in cscfg.zones:
if zone.name in avoidZones:
continue
for pod in zone.pods:
for cluster in pod.clusters:
for modifiedjob in jobModifier.addTests(env['build_number'], tests, self.throttle_job_count):
file = open('/root/cloud-autodeploy2/newcode/' + modifiedjob, 'r')
config = file.read()
file.close()
bash('rm -f /root/cloud-autodeploy2/newcode/%s' % modifiedjob)
if not j.job_exists(modifiedjob):
j.create_job(modifiedjob, config)
else:
j.delete_job(modifiedjob)
j.create_job(modifiedjob, config)
j.build_job(modifiedjob, {'BASEDIR': env['virtenvPath'],
'MGMT_SVR': env['hostip'],
'buildNumber': env['build_number'],
'zoneName': zone.name,
'hypervisor': cluster.hypervisor.lower(),
'zoneType': zone.networktype,
'configFileName': env['config_file'],
'token': 'bharat'})
self.waitForJobComplete(env['virtenvPath'], [zone.name])
env['hypervisor'] = '%s,%s' % (env['hypervisor'], cluster.hypervisor.lower())
break
break
if execOnOneZone:
break
tests = testMgr.getTests()
j.delete_job(modifiedjob)
reportAnalyserMap=self.getReportAnalysers(cscfg, env, execOnOneZone)
if(reRunFailedTests):
while retryCount > 0:
self.logger.info("checking if we need to re run any of the tests")
testsToReRun=[]
for key in reportAnalyserMap.keys():
tests=reportAnalyserMap[key].suitsToRerun
if(tests is None):
avoidZones.append(key)
else:
testMgr.addTestsToReRun(tests)
retryCount-=1
self.logger.info("zone name:%s The follwoing tests will be re run %s"%(key,tests))
if(len(testsToReRun)==0):
break
else:
self.execOnJenkins(env, testSpecifierString, mailto, reRunFailedTests, retryCount, False, execOnOneZone, postOnPr, testMgr, avoidZones)
if report and postOnPr:
for key in reportAnalyserMap.keys():
self.reportOnPr(reportAnalyserMap[key].generateTextReport2(), env)
elif report:
self.reportUsingJenkinsEmailPlugin(cscfg, env)
return env
except Exception as e:
self.logger.exception(e)
示例9: OptionParser
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
from jenkins import Jenkins
from hostImager import resourceManager
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-b", "--branch", action="store",
default="master", dest="branch",
help="The branch used for this coverage Information")
parser.add_option("-p", action="store",
default=None, dest="hypervisor",
help="The hypervisor type")
parser.add_option("-l", "--logname", action="store",
default=None, dest="logname",
help="The name of the log archive")
parser.add_option("-t", "--type", action="store",
default="bvt", dest="buildType",
help="The branch used for this coverage Information")
(options,args) = parser.parse_args()
j=Jenkins('http://jenkins-ccp.citrix.com','bharatk','BharatK')
print "triggering filebugs build to log bugs"
j.build_job('fileBugs', {'TYPE':options.buildType, 'HYP':options.hypervisor, 'version':options.branch, 'BUILD':options.logname,'token':'bharat'})
示例10: build_jobs
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def build_jobs(credentials, jobs, args):
jenkins = Jenkins('http://juju-ci.vapour.ws:8080', *credentials)
for job in jobs:
jenkins.build_job('cwr-test', job, token=args.cwr_test_token)
示例11: build_jobs
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def build_jobs(credentials, root, jobs):
jenkins = Jenkins('http://juju-ci.vapour.ws:8080', *credentials)
os_str = {"ubuntu": "", "osx": "-osx", "windows": "-windows"}
for job in jobs:
jenkins.build_job(
'compatibility-control{}'.format(os_str[job['client_os']]), job)
示例12: JenkinsBot
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
class JenkinsBot(BotPlugin):
def connect_to_jenkins(self):
self.jenkins = Jenkins(JENKINS_URL, username=JENKINS_USERNAME, password=JENKINS_PASSWORD)
@botcmd
def jenkins_list(self, mess, args):
"""List all jobs, optionally filter them using a search term."""
self.connect_to_jenkins()
search_term = args.strip().lower()
jobs = self.search_job(search_term)
return self.format_jobs(jobs)
@botcmd
def jenkins_running(self, mess, args):
"""List all running jobs."""
self.connect_to_jenkins()
jobs = [job for job in self.jenkins.get_jobs() if 'anime' in job['color']]
return self.format_running_jobs(jobs)
@botcmd
def jenkins_param(self, mess, args):
"""List Parameters for a given job."""
self.connect_to_jenkins()
if len(args) == 0:
return u'What Job would you like the parameters for?'
if len(args.split()) > 1:
return u'Please enter only one Job Name'
if self.jenkins.get_job_info(args)['actions'][0] == {}:
job_param = self.jenkins.get_job_info(args)['actions'][1]['parameterDefinitions']
else:
job_param = self.jenkins.get_job_info(args)['actions'][0]['parameterDefinitions']
return self.format_params(job_param)
@botcmd(split_args_with=None)
def jenkins_build(self, mess, args):
"""Build a Jenkins Job with the given parameters
Example: !jenkins build test_project FOO:bar
"""
self.connect_to_jenkins()
if len(args) == 0:
return u'What job would you like to build?'
parameters = self.build_parameters(args[1:])
self.jenkins.build_job(args[0], parameters)
running_job = self.search_job(args[0])
return 'Your job should begin shortly: {0}'.format(self.format_jobs(running_job))
def search_job(self, search_term):
return [job for job in self.jenkins.get_jobs() if search_term.lower() in job['name'].lower()]
def format_jobs(self, jobs):
if len(jobs) == 0:
return u'No jobs found.'
max_length = max([len(job['name']) for job in jobs])
return '\n'.join(['%s (%s)' % (job['name'].ljust(max_length), job['url']) for job in jobs]).strip()
def format_running_jobs(self, jobs):
if len(jobs) == 0:
return u'No running jobs.'
jobs_info = [self.jenkins.get_job_info(job['name']) for job in jobs]
return '\n\n'.join(['%s (%s)\n%s' % (job['name'], job['lastBuild']['url'], job['healthReport'][0]['description']) for job in jobs_info]).strip()
def format_params(self, job):
parameters = ''
for param in range (0, len(job)):
parameters = parameters + ("Type: {0}\nDescription: {1}\nDefault Value: {2}\nParameter Name: {3}\n_\n"
.format(job[param]['type'], job[param]['description'], str(job[param]['defaultParameterValue']['value']), job[param]['name']))
return parameters
def build_parameters(self, params):
if len(params) == 0:
return ast.literal_eval("{'':''}")
parameters_list = "{'"
for counter, param in enumerate(params):
param = param.split(':')
if counter < len(params) - 1:
#.........这里部分代码省略.........
示例13: execOnJenkins
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def execOnJenkins(self,env,testSpecifierString,mailto,execOnOneZone=True):
try:
testMgr=testManager(testSpecifierString,env['virtenvPath'])
jobModifier=modifyJOb()
modifiedjob=""
j=Jenkins('http://jenkins-ccp.citrix.com','bharatk','BharatK')
tests=testMgr.getTests()
if(tests==None):
raise Exception("found no tests to run")
while(not tests is None):
#trigger a jenkins job.
os.chdir(env['virtenvPath'])
self.logger.info("launching jenkins TestExecutor Job")
#createing testexecutorjobs for each zone.
cscfg=configGenerator.getSetupConfig(env['config_file'])
jobIdentifierList=[]
for zone in cscfg.zones:
for pod in zone.pods:
for cluster in pod.clusters:
modifiedjob=jobModifier.addTests(env['build_number'],tests)
file=open("/root/cloud-autodeploy2/newcode/"+modifiedjob,'r')
config=file.read()
file.close()
bash("rm -f /root/cloud-autodeploy2/newcode/%s"%modifiedjob)
if(not j.job_exists(modifiedjob)):
j.create_job(modifiedjob,config)
else:
j.reconfig_job(modifiedjob,config)
j.build_job(modifiedjob, {'BASEDIR':env['virtenvPath'], 'MGMT_SVR' : env['hostip'],'buildNumber':env['build_number'],'zoneName':zone.name,'hypervisor':cluster.hypervisor.lower(),'zoneType':zone.networktype,'configFileName':env['config_file'],'token':'bharat'})
jobIdentifierList.append(zone.name)
break
break
if (execOnOneZone):
break
self.waitForJobComplete(env['virtenvPath'],jobIdentifierList)
tests=testMgr.getTests()
j.delete_job(modifiedjob)
jobIdentifierList=[]
bugLoggerData=[]
time.sleep(30)
for zone in cscfg.zones:
self.logger.info(zone.name)
for pod in zone.pods:
for cluster in pod.clusters:
self.logger.info("creating a jeknins job to generate results and email notfication for hypervisor %s and zone %s"%(cluster.hypervisor, zone.name))
modifiedjob=jobModifier.modifyReportGenerator(env['build_number']+"_"+zone.name+"_"+cluster.hypervisor, mailto)
jobname=modifiedjob
file=open("/root/cloud-autodeploy2/newcode/"+modifiedjob,'r')
config=file.read()
file.close()
j.create_job(modifiedjob,config)
j.build_job(modifiedjob, {'buildNumber':env['build_number'],'BuildNo':env['build_number'], 'MGMT_SVR' : env['hostip'], 'BASEDIR':env['virtenvPath'], 'version':env['version'], 'BranchInfo':env['version'],\
'GitRepoUrl':env['repo_url'],'GitCommitId':env['commit_id'], 'CIRunStartDateTime':env['startTime'],'CIRunEndDateTime':time.strftime("%c"), 'WikiLinks':'https://cwiki.apache.org/confluence/display/CLOUDSTACK/Infrastructure%2CCI%2CSimulator%2CAutomation+Changes','hypervisor':cluster.hypervisor.lower(), 'HyperVisorInfo':cluster.hypervisor.lower(), 'zoneName':zone.name, 'BuildReport':"http://jenkins-ccp.citrix.com/job/"+jobname+"/1/testReport/",'token':'bharat'})
jobIdentifierList.append("report_"+zone.name)
jobDetails={"job_name":modifiedjob,"related_data_path":env['virtenvPath']}
self.resourceMgr.addJobDetails(jobDetails)
bugLoggerData.append({'hypervisor':cluster.hypervisor.lower(), 'branch':env['version'],'logname':cluster.hypervisor.lower()+'__Log_'+env['build_number'], 'type':'BVT'})
self.logger.info("bug logger data in zone looop %s"%bugLoggerData)
break
break
if (execOnOneZone):
#env['hypervisor':cluster.hypervisor.lower()]
break
self.logger.info("job identifier list", jobIdentifierList)
self.waitForJobComplete(env['virtenvPath'],jobIdentifierList)
#self.logger.info("deleting the reporter job on jenkins job_name=%s",jobname)
#j.delete_job(jobname)
self.logger.info("cleaning up the workspace")
bash("rm -f /root/cloud-autodeploy2/newcode/%s"%modifiedjob)
self.logger.info("running bug logger")
#self.runBugLogger(bugLoggerData)
#os.system("rm -rf %s"%(self.jenkinsWorkspace+"/"+jobname))
except Exception, e:
self.logger.error(e)
示例14: start_job
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import build_job [as 别名]
def start_job(root, job, juju_bin, user, password, number):
"""Use Jenkins API to start a job."""
jenkins = Jenkins('http://juju-ci.vapour.ws:8080', user, password)
job_params = {'juju_bin': juju_bin, 'sequence_number': number}
jenkins.build_job(job, job_params)