• 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()

  • 相关阅读:
    Linux 基本操作 (day2)
    Linux 简介(day1)
    python 反射、md5加密
    Python 简易版选课系统
    python 类与类之间的关系
    python 基本运算符
    python 基础操作--数据类型
    python初识
    生成器和生成器表达式
    SpringMvc测试框架详解----服务端测试
  • 原文地址:https://www.cnblogs.com/Qing-840/p/9285585.html
Copyright © 2020-2023  润新知