[Up]常用資訊

[重點文章] 重點文章 [重點文章] 重點文章

2020年4月19日 星期日

[Jenkins]jenkins批量克隆job

[Jenkins]jenkins批量克隆job

[Jenkins]jenkins批量克隆job.txt

脚本:
#!/usr/bin/env python
# -*- coding:utf-8 -*- 
#Author: qiantu
#qq 261767353

import jenkins
giturl="git@gitlab.lark.wiki:nbgold/"
template_xml="jenkins_job.xml"
view_name = "xiasha_BBB_"
server = jenkins.Jenkins('http://192.168.2.169:8080/jenkins/', username='admin', password='xxxxxxx')

import xml.etree.cElementTree as ET
job_list=["pay","member","weapon","trade","wealth","statistics","bops","napp","site","crm","channel","tiger","rams","activity","api","eagle","squirrel","wap","dragon","tengu"]
tree = ET.ElementTree(file=template_xml)

def create_job_file(model):
    for ele in tree.iterfind("properties/hudson.model.ParametersDefinitionProperty/parameterDefinitions/hudson.model.StringParameterDefinition/defaultValue"):
        ele.text=model
        ele.set("updated","up")
    for ele in tree.iterfind("scm/userRemoteConfigs/hudson.plugins.git.UserRemoteConfig/url"):
        ele.text=giturl+model+".git"
        ele.set("updated","up")
    file_name="jenkins_job_"+model+".xml"
    tree.write(file_name)
    return open(file_name).read()

for i in job_list:
    EMPTY_JOB_CONFIG=create_job_file(i)
    # print EMPTY_JOB_CONFIG

    new_job = server.create_job(view_name+i, EMPTY_JOB_CONFIG)
    # del_job=server.delete_job(view_name+i)

jenkins_job.xml 文件内容



  
  
  false
  
    
      
        
          model
          
          cms
        
        
          branch
          
          9d451b9b-9c6b-46ae-93be-636c522bac6f
          PT_BRANCH_TAG
          
          *
          .*
          NONE
          
          NONE
          false
        
      
    
  
  
    2
    
      
        git@gitlab.lark.wiki:nbgold/cms.git
        e646bdce-28d6-4a65-a169-f1a916517b24
      
    
    
      
        $branch
      
    
    false
    
    
  
  true
  false
  false
  false
  (System)
  
  false
  
    com.zzjr
    cms
  
  clean install -Dmaven.test.skip=true
  true
  false
  false
  false
  false
  false
  false
  false
  false
  -1
  false
  false
  true
  
  
  
  
  
  
  
    
      
        SSH: 
        
          
            
              ansible
              false
              
                
                  
                  ${model}-webapp/target/*.war
                  
                  
                  false
                  true
                  false
                  false
                  false
                  [, ]+
                  ansible ${model}_xsy_01 -m shell -a "mkdir -p /data/webapps/" --sudo
ansible ${model}_xsy_01 -m shell -a "echo 'zkserver=xxl01.niubangold.com:2181,xxl02.niubangold.com:2181,xxl03.niubangold.com:2181'>/data/webapps/xxl-conf.properties" --sudo
ansible ${model}_xsy_01 -m shell -a "service tomcat stop" --sudo
ansible ${model}_xsy_01 -m shell -a "rm -rf /usr/local/tomcat/webapps/*" --sudo

ansible ${model}_xsy_01 -m copy -a "src=/usr/local/war/${model}.war dest=/usr/local/tomcat/webapps/ROOT.war" --sudo

ansible ${model}_xsy_01 -m shell -a "service tomcat start" --sudo
                  120000
                  false
                
              
              false
              false
            
          
          false
          false
          false
          
        
      
    
  
  
    FAILURE
    2
    RED
    true
  

zzjr#2015

沒有留言:

張貼留言