本文整理汇总了Python中jenkins.Jenkins.create_node方法的典型用法代码示例。如果您正苦于以下问题:Python Jenkins.create_node方法的具体用法?Python Jenkins.create_node怎么用?Python Jenkins.create_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jenkins.Jenkins
的用法示例。
在下文中一共展示了Jenkins.create_node方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import create_node [as 别名]
def configure(self):
#self.logger.info("setting jenkins authentication method to use unix userdata")
#self.checkForSuccess(bash("cp %s/jenkis_auth_file /var/lib/jenkins"%currentDir))
#self.logger.info("setting jenkins password")
#self.logger.info("echo %s | sudo passwd jenkins --stdin"%self.jenkinsPasswd)
#self.checkForSuccess(bash("service jenkins restart"))
time.sleep(10)
self.logger.info("checking if auth config is successful")
j=Jenkins(self.jenkinsUrl, "admin", self.jenkinsPasswd)
try:
j.get_plugins()
except Exception as e:
self.logger.info("failed to retrive plugin info, may be auth problem")
self.logger.exception(e)
raise e
self.logger.info("auth config successful")
self.logger.info("installing requried plugins")
self.logger.info("reading from jenkins plugins file %s/jenkins_plugins.txt"%currentDir)
f=open('%s/jenkins_plugins.txt'%currentDir, 'r')
pluginsToInstall=f.read()
pluginsToInstall=pluginsToInstall.split('\n')
self.installPlugins(j,pluginsToInstall)
self.logger.info("Plugin installation complete")
self.logger.info("restarting jenkins")
self.restartJenkins()
self.logger.info("Creating CI jobs on jenkins")
for file in os.listdir(os.path.join(currentDir,'jenkins_job_templates')):
try:
if not j.job_exists(file):
f=open(os.path.join(currentDir,'jenkins_job_templates',file),'r')
config=f.read()
f.close()
self.logger.info("creating job %s, reading config from file %s"%(repr(file),os.path.join(currentDir,'jenkins_job_templates',file)))
j.create_job(file, config)
else:
self.logger.info("job %s already exists, not creating"%file)
except Exception as e:
self.logger.warn("failed to create job %s"%(file))
self.logger.exception(e)
self.logger.info("created all CI jobs")
self.logger.info("Adding driverVM as node in jenkins")
params = {
'port': '22',
'username': 'jenkins',
'credentialsId':'abe3f139-77bd-4db4-824b-1c79d5205d8b',
'host':self.config['nodes']['driverVM']['ip']
}
self.addPasswdToCredential(j,"vagrant")
self.checkForSuccess(bash("cp %s /var/lib/jenkins/."%(os.path.join(currentDir,"jenkins_credentials","credentials.xml"))))
j.create_node('driverVM', numExecutors=20, nodeDescription="CI slave VM", remoteFS='/automation/jenkins', labels='driverVM', exclusive=True,launcher=jenkins.LAUNCHER_SSH, launcher_params=params)
self.logger.info("jenkins install complete")
示例2: JenkinsBot
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import create_node [as 别名]
#.........这里部分代码省略.........
return 'Oops, {0}'.format(e)
return 'Your job has been enabled.'
@botcmd(split_args_with=None)
def jenkins_disablejob(self, mess, args):
"""Disable a Jenkins Job.
Example: !jenkins disablejob foo
"""
if len(args) < 1: # No job name
return 'Oops, I need the name of the job you want me to disable.'
self.connect_to_jenkins()
try:
self.jenkins.disable_job(args[0])
except JenkinsException as e:
return 'Oops, {0}'.format(e)
return 'Your job has been disabled.'
@botcmd(split_args_with=None)
def jenkins_createnode(self, mess, args):
"""Create a Jenkins Node with a JNLP Launcher with optionnal labels.
Example: !jenkins createnode runner-foo-laptop /home/foo # without labels
Example: !jenkins createnode runner-bar-laptop /home/bar linux docker # with labels
"""
if len(args) < 1: # No node name
return 'Oops, I need a name and a working dir for your new node.'
self.connect_to_jenkins()
try:
self.jenkins.create_node(
name=args[0],
remoteFS=args[1],
labels=' '.join(args[2:]),
exclusive=True,
launcher=LAUNCHER_JNLP)
except JenkinsException as e:
return 'Oops, {0}'.format(e)
return 'Your node has been created: {0}/computer/{1}'.format(
self.config['URL'], args[0])
@botcmd(split_args_with=None)
def jenkins_deletenode(self, mess, args):
"""Delete a Jenkins Node.
Example: !jenkins deletenode runner-foo-laptop
"""
if len(args) < 1: # No node name
return 'Oops, I need the name of the node you want me to delete.'
self.connect_to_jenkins()
try:
self.jenkins.delete_node(args[0])
except JenkinsException as e:
return 'Oops, {0}'.format(e)
return 'Your node has been deleted.'
@botcmd(split_args_with=None)
def jenkins_enablenode(self, mess, args):
"""Enable a Jenkins Node.
Example: !jenkins enablenode runner-foo-laptop