zoukankan      html  css  js  c++  java
  • python jenkins api

    #!/usr/bin/python
    import sys, time
    import shutil, commands
    #coding=utf-8
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')
    import jenkins

    config_file = 'jenkins_list.txt'
    jenkins_url='http://qc-xxx.xxxx.com/'
    user_name='user'
    pass_word='password'
    server = jenkins.Jenkins(jenkins_url, username=user_name, password=pass_word)
    temp_job_name='saas-kf-aal-online'
    tem_xml_file='tem.xml'


    #print server.get_whoami()

    #server.copy_job("xx-xx-xx-online", "xx-xx-copy-xxx-online")
    #print server.get_job_info("saas-kf-copy-aal-online", depth=2, fetch_all_builds=True)
    #print server.get_job_config("saas-kf-copy-aal-online")
    #with open('aa.xml', 'r') as xml_file:
    # config_data = xml_file.read()
    #server.reconfig_job("saas-kf-copy-aal-online",config_data)

    def commands_shell(cmd):
    (status, output) = commands.getstatusoutput(cmd)
    print status, output
    return status, output


    file = open(config_file)


    while 1:
    line = file.readline()
    if not line:
    break
    line_str = line.split(',')
    job_name = line_str[0].strip()
    git_url = line_str[1].strip()
    target_dir = line_str[2].strip()
    job_name_xml='job_name/' + job_name + '.xml'
    print job_name,git_url
    ##copy tem file
    shutil.copy(tem_xml_file, job_name_xml)
    cmd = "sed -i 's#TMPGITURL#%s#g' %s" % (git_url, job_name_xml)
    print cmd
    ret = commands_shell(cmd)

    print ret
    cmd = "sed -i 's#TARGET_DIR#%s#g' %s" % (target_dir, job_name_xml)

    ret = commands_shell(cmd)
    print ret

    config_data = ''
    with open(job_name_xml, 'r') as xml_file:
    config_data = xml_file.read()
    #server.reconfig_job("saas-kf-copytests-aal-online",config_data)
    server.create_job(job_name, config_data)


    file.close()

  • 相关阅读:
    快捷方式总结
    高版本数据库数据附加到低版本数据库中的解决方案
    boost_1_63_0在Win10上VS2015编译
    基于ACE的TAO开发---一个简单的入门实例-----VS2008(二)
    基于ACE的TAO开发---一个简单的入门实例-----VS2008(一)
    Wireshark抓包过滤
    Wireshark抓本地回环
    使用UMDH进行内心泄露分析
    类设计者的核查表
    关于数据同步,窗口同步之类
  • 原文地址:https://www.cnblogs.com/Qing-840/p/9285585.html
Copyright © 2011-2022 走看看