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

python jenkins api的更多相关文章

  1. 利用 Java 操作 Jenkins API 实现对 Jenkins 的控制详解

    本文转载自利用 Java 操作 Jenkins API 实现对 Jenkins 的控制详解 导语 由于最近工作需要利用 Jenkins 远程 API 操作 Jenkins 来完成一些列操作,就抽空研究 ...

  2. 用 Identity Server 4 (JWKS 端点和 RS256 算法) 来保护 Python web api

    目前正在使用asp.net core 2.0 (主要是web api)做一个项目, 其中一部分功能需要使用js客户端调用python的pandas, 所以需要建立一个python 的 rest api ...

  3. shell中调用jenkins API批量运行历史任务

    shell中调用jenkins API批量运行jenkins带参数的任务: #!/bin/sh #startdate=20150127 startdate=20150201 while [ " ...

  4. Python DB API 连接数据库

    Python DB API Mysql,Oracle,SqlServer 不关闭,会浪费资源.

  5. Python调用API接口的几种方式 数据库 脚本

    Python调用API接口的几种方式 2018-01-08 gaoeb97nd... 转自 one_day_day... 修改 微信分享: 相信做过自动化运维的同学都用过API接口来完成某些动作.AP ...

  6. Python调用API接口的几种方式

    Python调用API接口的几种方式 相信做过自动化运维的同学都用过API接口来完成某些动作.API是一套成熟系统所必需的接口,可以被其他系统或脚本来调用,这也是自动化运维的必修课. 本文主要介绍py ...

  7. Python Elasticsearch api,组合过滤器,term过滤器,正则查询 ,match查询,获取最近一小时的数据

    Python Elasticsearch api   描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下 ...

  8. python3 jenkins api操作

    一.安装依赖包 pip install python-jenkins 二.常用操作 0.调用jenkins(以下用的server都是这里的环境) import jenkins server = jen ...

  9. 如何用 Python 和 API 收集与分析网络数据?

    摘自 https://www.jianshu.com/p/d52020f0c247 本文以一款阿里云市场历史天气查询产品为例,为你逐步介绍如何用 Python 调用 API 收集.分析与可视化数据.希 ...

随机推荐

  1. Web应急:网站首页被篡改

    网站首页被非法篡改,是的,就是你一打开网站就知道自己的网站出现了安全问题,网站程序存在严重的安全漏洞,攻击者通过上传脚本木马,从而对网站内容进行篡改.而这种篡改事件在某些场景下,会被无限放大. 现象描 ...

  2. asp.net core不通过构造方法从容器中获取对象及解决通过这种方法NLog获取对象失败的问题

    一般想从容器中获取对象,我们都是通过构造方法获取对象,但有些条件不允许不能通过构造方法获取对象,我们必须单独从容器中单独创建获取找个对象,这样我们就不行把找个容器静态保存起来供全局diaoy 一. 简 ...

  3. .Net Core实战教程(三):使用Supervisor配置守护进程

    安装Supervisor yum install python-setuptools easy_install supervisor 配置Supervisor mkdir /etc/superviso ...

  4. desktoplayer.exe病毒及d:\w7rtm\base\wcp\sil\merged\ntu\ntsystem.cpp的解决方案

    1 前言 该病毒,使用360普通杀毒杀不出来,而且会伴随以下问题: a.电脑蓝屏问题[多图] b.fsc/scannow CbS.log d:\w7rtm\base\wcp\sil\merged\nt ...

  5. python 排序 堆排序

    算法思想 : 堆排序利用堆数据结构设计的一种排序算法,堆是一种近似完全二叉树的结构,同时满足堆积的性质,即对于任意的i均有ki>=k(2i+1),ki>=k(2i+2) 步骤: 将数组转化 ...

  6. Redis之缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级

    目录 Redis之缓存雪崩.缓存穿透.缓存预热.缓存更新.缓存降级 1.缓存雪崩 2.缓存穿透 3.缓存预热 4.缓存更新 5.缓存降级 Redis之缓存雪崩.缓存穿透.缓存预热.缓存更新.缓存降级 ...

  7. tcp 3次握手和4次挥手

    TCP标志位 (参考来源:https://blog.csdn.net/ltstud/article/details/73995933和 https://blog.csdn.net/weixin_308 ...

  8. Android 工作流提交审批填写审批意见PopWindow工具类

    公司的项目中几乎都会有走工作流这个环节,为了提高效率,现在特意把弹出的填写审批意见PopWindow改转成工具类,提高效率,免得下次又得整.先看运行效果.

  9. 定时任务突然中止,告警:Thread starvation or clock leap detected

    1.背景 定时任务告警信息如下: 02:38:24.112 [HikariPool-1 housekeeper] WARN  com.zaxxer.hikari.pool.HikariPool - H ...

  10. elastic常用工具

    elasticsearch 常用工具: elasticsearch-dump :备份 elasticsearch-head :数据展示.操作平台 elasticsearch-head github 地 ...