博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python jenkins api
阅读量:6977 次
发布时间:2019-06-27

本文共 1658 字,大约阅读时间需要 5 分钟。

#!/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()

 

转载于:https://www.cnblogs.com/Qing-840/p/9285585.html

你可能感兴趣的文章
第四章 软件架构演化
查看>>
Vsftp给每个用户建立单独的配置文件
查看>>
MySQL——修改root密码的4种方法(以windows为例)
查看>>
sublime搜索和替换--多文件搜索替换
查看>>
(七):处理MFC
查看>>
【算法拾遗】大数相加(不开辟额外空间)
查看>>
Python正则表达式精讲
查看>>
Python——Beautiful Soup 4.2.0 中文文档
查看>>
Python字符串拼接、截取及替换方法总结
查看>>
3.Session安装配置
查看>>
MXNet学习:预测结果-识别单张图片
查看>>
JAVA微信开发-新手接入指南
查看>>
作业一
查看>>
virsh命令来创建虚拟机
查看>>
7.1.11、each 指针复位
查看>>
DPDK-----初识
查看>>
说说 PWA 和微信小程序--Progressive Web App
查看>>
kill命令"-1"这个参数到底是杀进程还是reload?(转)
查看>>
struts2 result type=(chain、dispatcher、redirect、redirect-action)
查看>>
mysql foreign key(外键)
查看>>