“Python-jenkins”的版本间的差异
跳到导航
跳到搜索
第16行: | 第16行: | ||
</pre> | </pre> | ||
− | = | + | = 单个copy jobs = |
<pre> | <pre> | ||
cat copyjob.py | cat copyjob.py | ||
第24行: | 第24行: | ||
#user = server.get_whoami() | #user = server.get_whoami() | ||
server.copy_job('testpipe','evanpipe1') | server.copy_job('testpipe','evanpipe1') | ||
+ | #info = server.get_job_info('testpipe') | ||
+ | #print(info) | ||
+ | |||
+ | </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') | #info = server.get_job_info('testpipe') | ||
#print(info) | #print(info) |
2021年9月30日 (四) 03:15的版本
pip3 install python-jenkins
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)
R
https://python-jenkins.readthedocs.io/en/latest/examples.html