当前位置:网站首页>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.*')
边栏推荐
- 什么是数字孪生智慧城市应用场景
- docker+bridge+redis master-slave+sentry mode
- Y86. Chapter iv Prometheus giant monitoring system and the actual combat, Prometheus storage (17)
- 【21天学习挑战赛】顺序查找
- 缓存穿透、缓存击穿、缓存雪崩以及解决方案
- 7-1 LVS+NAT 负载均衡群集,NAT模式部署
- The video of machine learning to learn [update]
- 劝退背后。
- 7.LVS负载均衡群集之原理叙述
- 2 Gigabit Optical + 6 Gigabit Electric Rail Type Managed Industrial Ethernet Switch Supports X-Ring Redundant Ring One-key Ring Switch
猜你喜欢
7-2 LVS+DR概述与部署
Significant differences between Oracle and Postgresql in PLSQL transaction rollback
42. 接雨水
出现504怎么办?由于服务器更新导致的博客报504错误[详细记录]
帮助企业实现数字化转型成功的八项指导原则
Postgresql source code (66) insert on conflict grammar introduction and kernel execution process analysis
Simple operation of the file system
y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)
7-3 LVS+Keepalived Cluster Description and Deployment
"Introduction to nlp + actual combat: Chapter 8: Using Pytorch to realize handwritten digit recognition"
随机推荐
马尔可夫链
MRS: Introduction to the use of Alluxio
How to open a CITIC Securities online account?is it safe?
FFmpeg —— 录制麦克风声音(附源码)
Significant differences between Oracle and Postgresql in PLSQL transaction rollback
TL431的基本特性以及振荡电路
y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)
4-way two-way HDMI integrated business high-definition video optical transceiver 8-way HDMI high-definition video optical transceiver
Metaverse "Drummer" Unity: Crazy expansion, suspense still exists
Power button (LeetCode) 215. The first K largest elements in the array (2022.08.03)
如何动态添加script依赖的脚本
"Introduction to nlp + actual combat: Chapter 8: Using Pytorch to realize handwritten digit recognition"
自定义通用分页标签01
Eight guiding principles to help businesses achieve digital transformation success
Mobile payment online and offline payment scenarios
SQL query String field less than 10 how to check
new Date converts strings into date formats Compatible with IE, how ie8 converts strings into date formats through new Date, how to replace strings in js, and explain the replace() method in detail
typescript type 和 interface 的区别
基本表单验证流程
How class only static allocation and dynamic allocation