本文整理汇总了Python中jenkins.Jenkins.job方法的典型用法代码示例。如果您正苦于以下问题:Python Jenkins.job方法的具体用法?Python Jenkins.job怎么用?Python Jenkins.job使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jenkins.Jenkins
的用法示例。
在下文中一共展示了Jenkins.job方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: JenkinsControl
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import job [as 别名]
class JenkinsControl(object):
war = pjoin(here, "tmp/jenkins.war")
cli = pjoin(here, "tmp/jenkins-cli.jar")
home = pjoin(here, "tmp/jenkins")
def __init__(self, addr="127.0.0.1:60888", cport="60887"):
self.addr, self.port = addr.split(":")
self.url = "http://%s" % addr
self.py = Jenkins(self.url)
def start_server(self):
cmd = pjoin(here, "./bin/start-jenkins.sh 1>/dev/null 2>&1")
env = {
"JENKINS_HOME": self.home,
"JENKINS_PORT": self.port,
"JENKINS_CPORT": self.cport,
"JENKINS_ADDR": self.addr,
}
check_call(cmd, shell=True, env=env)
def shutdown_server(self):
cmd = "echo 0 | nc %s %s" % (self.addr, self.cport)
check_call(cmd, shell=True)
def clean_home(self):
rmtree(self.home)
def createjob(self, name, configxml_fn):
configxml = open(configxml_fn).read().encode("utf8")
self.py.job_create(name, configxml)
def getjobs(self):
return {i.name: i for i in self.py.jobs}
def enabled(self, name):
return self.py.job(name).info["buildable"]
def job_etree(self, job):
res = self.py.job(job).config
res = etree.fromstring(res)
return res
示例2: JenkinsControl
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import job [as 别名]
class JenkinsControl(object):
war = pjoin(here, 'tmp/jenkins.war')
cli = pjoin(here, 'tmp/jenkins-cli.jar')
home = pjoin(here, 'tmp/jenkins')
def __init__(self, addr='127.0.0.1:60888', cport='60887'):
self.addr, self.port = addr.split(':')
self.url = 'http://%s' % addr
self.py = Jenkins(self.url)
def start_server(self):
cmd = pjoin(here, './bin/start-jenkins.sh 1>/dev/null 2>&1')
env = {'JENKINS_HOME': self.home,
'JENKINS_PORT': self.port,
'JENKINS_CPORT': self.cport,
'JENKINS_ADDR': self.addr}
check_call(cmd, shell=True, env=env)
def shutdown_server(self):
cmd = 'echo 0 | nc %s %s' % (self.addr, self.cport)
check_call(cmd, shell=True)
def clean_home(self):
rmtree(self.home)
def createjob(self, name, configxml_fn):
configxml = open(configxml_fn).read().encode('utf8')
self.py.job_create(name, configxml)
def getjobs(self):
return {i.name: i for i in self.py.jobs}
def enabled(self, name):
return self.py.job(name).info['buildable']
def job_etree(self, job):
res = self.py.job(job).config
res = etree.fromstring(res)
return res
示例3: JenkinsTrigger
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import job [as 别名]
class JenkinsTrigger(object):
"""
A class to trigger builds on Jenkins and print the results.
:param token: The token we need to trigger the build. If you do not have this token, ask in IRC.
"""
def __init__(self, token):
"""
Create the JenkinsTrigger instance.
"""
self.token = token
self.repo_name = get_repo_name()
self.jenkins_instance = Jenkins(JENKINS_URL)
def trigger_build(self):
"""
Ask our jenkins server to build the "Branch-01-Pull" job.
"""
bzr = Popen(('bzr', 'whoami'), stdout=PIPE, stderr=PIPE)
raw_output, error = bzr.communicate()
# We just want the name (not the email).
name = ' '.join(raw_output.decode().split()[:-1])
cause = 'Build triggered by %s (%s)' % (name, self.repo_name)
self.jenkins_instance.job(OpenLPJobs.Branch_Pull).build({'BRANCH_NAME': self.repo_name, 'cause': cause},
token=self.token)
def print_output(self):
"""
Print the status information of the build triggered.
"""
print('Add this to your merge proposal:')
print('--------------------------------')
bzr = Popen(('bzr', 'revno'), stdout=PIPE, stderr=PIPE)
raw_output, error = bzr.communicate()
revno = raw_output.decode().strip()
print('%s (revision %s)' % (get_repo_name(), revno))
for job in OpenLPJobs.Jobs:
if not self.__print_build_info(job):
print('Stopping after failure')
break
def open_browser(self):
"""
Opens the browser.
"""
url = self.jenkins_instance.job(OpenLPJobs.Branch_Pull).info['url']
# Open the url
Popen(('xdg-open', url), stderr=PIPE)
def __print_build_info(self, job_name):
"""
This helper method prints the job information of the given ``job_name``
:param job_name: The name of the job we want the information from. For example *Branch-01-Pull*. Use the class
variables from the :class:`OpenLPJobs` class.
"""
is_success = False
job = self.jenkins_instance.job(job_name)
while job.info['inQueue']:
time.sleep(1)
build = job.last_build
build.wait()
if build.info['result'] == 'SUCCESS':
# Make 'SUCCESS' green.
result_string = '%s%s%s' % (Colour.GREEN_START, build.info['result'], Colour.GREEN_END)
is_success = True
else:
# Make 'FAILURE' red.
result_string = '%s%s%s' % (Colour.RED_START, build.info['result'], Colour.RED_END)
url = build.info['url']
print('[%s] %s' % (result_string, url))
return is_success