欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python的Jenkins接口調(diào)用方式

 更新時間:2020年05月12日 10:19:16   作者:很長很長的名字  
這篇文章主要介紹了python的Jenkins接口調(diào)用方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

本來非常喜歡偷懶

最好就是不干活那種

所以最近在研究把Jenkins模塊集成起來

做成傻瓜界面這樣就給他們用

本人Python搓望大神不要噴,多多指導(dǎo)

jenkins的Python模塊模塊安裝

pip:
pip install python-jenkins

easy_install:
easy_install python-jenkins

使用:

class jenkins_tools():
  def __init__(self):
    cf = get_conf()
    self.username = cf.get('jenkins', 'username')
    self.password = cf.get('jenkins', 'password')
    self.php_jenkins = '''			#本屌自己的jenkins的conf文件
    <project>				#這里可以去抄jenkins的項目文件夾里面的配置文件
     <actions/>				#記得不要加xml頭,源碼哪里幫我們加了,自己加就是作死
     <description></description>		#項目需求不一樣,配置文件也不一樣,你們不要抄我的
     <keepDependencies>false</keepDependencies>
     <properties>
      <hudson.model.ParametersDefinitionProperty>
       <parameterDefinitions>
        <hudson.model.StringParameterDefinition>
         <name>Branch</name>
         <description></description>
         <defaultValue>%s</defaultValue>
        </hudson.model.StringParameterDefinition>
       </parameterDefinitions>
      </hudson.model.ParametersDefinitionProperty>
     </properties>
     <scm class="hudson.scm.NullSCM"/>
     <canRoam>true</canRoam>
     <disabled>false</disabled>
     <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
     <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
     <triggers/>
     <concurrentBuild>false</concurrentBuild>
     <builders>
      <hudson.tasks.Shell>
       <command>xxxxxxx</command>	
      </hudson.tasks.Shell>
     </builders>
     <publishers/>
     <buildWrappers/>
    </project>
      '''
    self.java_newjenkins = '''		#本屌的另外一個jenkins的conf文件
      <project>
       <actions/>
       <description></description>
       <keepDependencies>false</keepDependencies>
       <properties>
        <hudson.model.ParametersDefinitionProperty>
         <parameterDefinitions>
          <hudson.model.StringParameterDefinition>
           <name>Branch</name>
           <description></description>
           <defaultValue>%s</defaultValue>
          </hudson.model.StringParameterDefinition>
         </parameterDefinitions>
        </hudson.model.ParametersDefinitionProperty>
       </properties>
       <scm class="hudson.scm.NullSCM"/>
       <canRoam>true</canRoam>
       <disabled>false</disabled>
       <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
       <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
       <triggers/>
       <concurrentBuild>false</concurrentBuild>
       <builders>
        <hudson.tasks.Shell>
         <command>xxxx</command>	
        </hudson.tasks.Shell>
       </builders>
       <publishers/>
       <buildWrappers/>
      </project>
        '''
  def __conn_jenkins_server(self, url):
    try:
	  #獲得一個jenkins的操作實例
      server = jenkins.Jenkins(url, username=self.username, password=self.password)
      return server
    except Exception:
      logging.warning('login jenkins failed!')
      return None
	
  def create_project(self, host_ip, project_name, git_path, git_branch, url, environment):
    server = self.__conn_jenkins_server(url)
    if server:
      server.create_job(project_name, self.php_jenkins)	#參數(shù)1寫的是項目名稱,參數(shù)2是xml文檔
      return True
    else:
      return None
 
  def project_built(self, url, project_name, git_branch):	#這個函數(shù)作用是構(gòu)建項目
    server = self.__conn_jenkins_server(url)		
    server.build_job(project_name, {'Branch': git_branch})
 
  def check_project_exist(self, project_name, url):		#這個函數(shù)是檢查項目是否已經(jīng)存在雖然寫得很挫忘不要見怪
    server = self.__conn_jenkins_server(url)
    name = server.get_job_name(project_name)
    if name is None:
      return False
    return True

詳細(xì)可以看官方文檔:http://python-jenkins.readthedocs.io/en/latest/api.html

補充知識:python調(diào)用jenkinsapi

在通過python 調(diào)用jenkinsapi的時候,需要對一些作業(yè)進行定時對構(gòu)建

報錯:

<title>Error 403 No valid crumb was included in the request</title>\n</head>\n<body><h2>HTTP ERROR 403</h2>

原因是在jenkins的安全配置里勾選里下面這個選項,在預(yù)防跨站點請求,將其勾掉即可。

以上這篇python的Jenkins接口調(diào)用方式就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論