“Python-jenkins”的版本间的差异
跳到导航
跳到搜索
(未显示同一用户的12个中间版本) | |||
第1行: | 第1行: | ||
pip3 install python-jenkins | pip3 install python-jenkins | ||
+ | |||
+ | =install= | ||
+ | pip install python-jenkins --break-system-packages #sometime | ||
=Example 1: Get version of Jenkins= | =Example 1: Get version of Jenkins= | ||
第16行: | 第19行: | ||
</pre> | </pre> | ||
− | = | + | |
+ | = 单个copy jobs = | ||
<pre> | <pre> | ||
cat copyjob.py | cat copyjob.py | ||
第29行: | 第33行: | ||
</pre> | </pre> | ||
− | = | + | = 多个 copy jobs = |
+ | <pre> | ||
+ | import jenkins | ||
+ | |||
+ | server = jenkins.Jenkins("http://192.168.10.100:8080/", "root", "23456") | ||
+ | #user = server.get_whoami() | ||
+ | list = ['evan1','evan2','evan3'] | ||
+ | for i in list: | ||
+ | server.copy_job('testpipe',i) | ||
+ | |||
+ | #server.copy_job('testpipe','evanpipe2') | ||
+ | #server.copy_job('testpipe','evanpipe3') | ||
+ | #server.copy_job('testpipe','evanpipe4') | ||
+ | #info = server.get_job_info('testpipe') | ||
+ | #print(info) | ||
+ | |||
+ | </pre> | ||
+ | [https://stackoverflow.com/questions/11480042/python-3-turn-range-to-a-list Python 3 turn range to a list] | ||
+ | |||
+ | =build jobs= | ||
+ | <pre> | ||
+ | |||
+ | #注意 默认是没 交互参数什么的 | ||
+ | |||
+ | #!/usr/bin/python3 | ||
+ | # -*- coding: UTF-8 -*- | ||
+ | # list格式一定得如下 ['intra_pipe_task','intra_pipe_server'] 所以有了这个脚本 ,把文件读取后转为 list格式适合的的 | ||
+ | import jenkins | ||
+ | import sys | ||
+ | |||
+ | server = jenkins.Jenkins("http://192.168.10.100:8080/", "ops", "dddsdf1") | ||
+ | |||
+ | myre=[] | ||
+ | with open("myjobslist","r") as f: | ||
+ | myre = [l.strip() for l in f] | ||
+ | |||
+ | #print(myre) | ||
+ | |||
+ | for i in myre: | ||
+ | server.build_job(i) | ||
+ | |||
+ | f.close | ||
+ | #server.build_job('empty') | ||
+ | |||
+ | #先把文件读取并转为list | ||
+ | |||
+ | cat myjobslist | ||
+ | intra_pipe-product-server | ||
+ | intra_pipe_evaluating-server | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | #这个写到list 不方便 is old | ||
+ | |||
+ | #!/usr/bin/python3 | ||
+ | # -*- coding: UTF-8 -*- | ||
+ | import jenkins | ||
+ | |||
+ | |||
+ | server = jenkins.Jenkins("http://192.168.10.100:8080/", "root", "password") | ||
+ | |||
+ | jobslist=['intra_pipe_task','intra_pipe_server'] | ||
+ | for i in jobslist: | ||
+ | server.build_job(i) | ||
+ | |||
+ | |||
+ | #server.build_job('empty') | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | =Reference= | ||
https://python-jenkins.readthedocs.io/en/latest/examples.html | https://python-jenkins.readthedocs.io/en/latest/examples.html | ||
+ | |||
+ | [[category:devops]] [[category:jenkins]] [[category:python]] |
2024年10月22日 (二) 01:57的最新版本
pip3 install python-jenkins
目录
install
pip install python-jenkins --break-system-packages #sometime
Example 1: Get version of Jenkins
This is an example showing how to connect to a Jenkins instance and retrieve the Jenkins server version.
import jenkins server = jenkins.Jenkins('http://localhost:8080', username='myuser', password='mypassword') user = server.get_whoami() version = server.get_version() print('Hello %s from Jenkins %s' % (user['fullName'], version)) #Hello 运维 from Jenkins 2.263.1
单个copy jobs
cat copyjob.py import jenkins server = jenkins.Jenkins("http://jenkins.com/", "ops", "23456777") #user = server.get_whoami() server.copy_job('testpipe','evanpipe1') #info = server.get_job_info('testpipe') #print(info)
多个 copy jobs
import jenkins server = jenkins.Jenkins("http://192.168.10.100:8080/", "root", "23456") #user = server.get_whoami() list = ['evan1','evan2','evan3'] for i in list: server.copy_job('testpipe',i) #server.copy_job('testpipe','evanpipe2') #server.copy_job('testpipe','evanpipe3') #server.copy_job('testpipe','evanpipe4') #info = server.get_job_info('testpipe') #print(info)
build jobs
#注意 默认是没 交互参数什么的 #!/usr/bin/python3 # -*- coding: UTF-8 -*- # list格式一定得如下 ['intra_pipe_task','intra_pipe_server'] 所以有了这个脚本 ,把文件读取后转为 list格式适合的的 import jenkins import sys server = jenkins.Jenkins("http://192.168.10.100:8080/", "ops", "dddsdf1") myre=[] with open("myjobslist","r") as f: myre = [l.strip() for l in f] #print(myre) for i in myre: server.build_job(i) f.close #server.build_job('empty') #先把文件读取并转为list cat myjobslist intra_pipe-product-server intra_pipe_evaluating-server #这个写到list 不方便 is old #!/usr/bin/python3 # -*- coding: UTF-8 -*- import jenkins server = jenkins.Jenkins("http://192.168.10.100:8080/", "root", "password") jobslist=['intra_pipe_task','intra_pipe_server'] for i in jobslist: server.build_job(i) #server.build_job('empty')
Reference
https://python-jenkins.readthedocs.io/en/latest/examples.html