当前位置:网站首页>Jenkins export and import Job Pipeline
Jenkins export and import Job Pipeline
2022-08-04 04:14:00 【LeoHsiao1】
Jenkins Web page can be manually modify Job Pipeline 配置 ,But large quantities when a change is more troublesome.There are several kinds of batch modification method:
- 到 jenkins_home 安装目录下,执行 zip -r jobs.zip jobs/*/config.xml ,可以导出 Job 配置文件.不过修改了之后,需要重启 Jenkins 才会生效.
- 通过 Jenkins API 导出、导入 Job 配置文件.
In this paper, we give the second method Python 示例代码:
""" - The script is used for export、导入 Jenkins 的 Pipeline 脚本,保存为 XML 文件 - 需要安装 pip install jenkinsapi - Import the configuration file contains the ASCII 码时,需要修改 update_config() 的定义代码,注释 config = str(config) 一行 """
import os
import re
from jenkinsapi.jenkins import Jenkins
# 连接 Jenkins
jk = Jenkins('https://jenkins.test.com/', username='***', password='***', timeout=10, useCrumb=True)
config_suffix = '.xml'
def export_job(job_pattern='.*', work_dir='.'):
for job_name in jk.keys():
if not re.findall(job_pattern, job_name):
continue
config = jk.get_job(job_name).get_config()
config_file = os.path.normpath(os.path.join(work_dir, job_name + config_suffix))
os.makedirs(os.path.dirname(config_file), exist_ok=True)
with open(config_file, 'w', encoding='utf-8') as f:
f.write(config)
def import_job(job_pattern='.*', work_dir='.'):
for line in os.walk(work_dir, onerror=print):
sub_dir,dir_list,file_list = line
for file in file_list:
if file[-len(config_suffix):] != config_suffix:
continue
# 获取 job name
path_fileds = list(os.path.split(sub_dir)) + [file]
job_name = '/'.join(path_fileds).removeprefix(work_dir.replace('\\', '/')).removeprefix('/').removesuffix(config_suffix)
# 读取 job 的配置文件
if not re.findall(job_pattern, job_name):
continue
config_file = os.path.join(sub_dir, file)
with open(config_file, 'r', encoding='utf-8') as f:
config = f.read()
# 导入 job 配置
if jk.has_job(job_name):
jk.get_job(job_name).update_config(config.encode('utf-8'))
print('已导入Job:', job_name)
else:
print('Jenkins不存在该Job:', job_name)
# 自动创建 Job 会失败,目前只能导入 Jenkins Has been created Job
# jk.create_job(job_name, config)
# 执行导出、导入
export_job('test.*')
import_job('test.*')
边栏推荐
- 6口全千兆二层网管型工业以太网交换机千兆2光4电光纤自愈ERPS环网交换机
- Jenkins 导出、导入 Job Pipeline
- Functions, recursion and simple dom operations
- 【Ryerson情感说话/歌唱视听数据集(RAVDESS) 】
- 看DevExpress丰富图表样式,如何为基金公司业务创新赋能
- MySQL查询优化与调优
- 图像处理之Bolb分析(一)
- 基于 SSE 实现服务端消息主动推送解决方案
- Embedded database development programming MySQL (full)
- 10 Convolutional Neural Networks for Deep Learning 3
猜你喜欢
随机推荐
马尔可夫链
文件系统的简单操作
PL/SQL Some Advanced Fundamental
Implementing a server-side message active push solution based on SSE
2003. 每棵子树内缺失的最小基因值 DFS
【源码】使用深度学习训练一个游戏
函数,递归以及dom简单操作
企业直播风起:目睹聚焦产品,微赞拥抱生态
本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现
7-3 LVS+Keepalived Cluster Description and Deployment
Take care of JVM performance optimization (own note version)
Explain detailed explanation and practice
基于 SSE 实现服务端消息主动推送解决方案
力扣(LeetCode)215. 数组中的第K个最大元素(2022.08.03)
7-1 LVS+NAT 负载均衡群集,NAT模式部署
【C语言进阶】程序环境和预处理
Significant differences between Oracle and Postgresql in PLSQL transaction rollback
深度学习——以CNN服装图像分类为例,探讨怎样评价神经网络模型
自定义通用分页标签02
XSS相关知识点









