如果你使用 Python 2.7.12,Jenkins版本为Jenkins ver. 2.22,,你使用我上面一种提到的改削的以下代码可以进行Jenkins的job复制
但如果你python版本为2.7.5,Jenkins版本为Jenkins ver. 2.73.1,或者呈现使用API错误的问题jenkinsapi.custom_exceptions.JenkinsAPIException,使用以下代码进行
from __future__ import print_function from jenkinsapi.jenkins import Jenkins from jenkinsapi.utils.crumb_requester import CrumbRequester import sys reload(sys) sys.setdefaultencoding(‘utf8‘) jenkins_url = ‘域名/jenkins/‘ jenkins_user = ‘admin‘ jenkins_password = ‘123‘ def copy_jenkinsjob(job_name): jenkins = Jenkins(jenkins_url, username=jenkins_user, password=jenkins_user, requester=CrumbRequester(username=jenkins_user, password=jenkins_password, baseurl=jenkins_url)) jenkins.copy_job(‘demo‘,job_name) if __name__==‘__main__‘: print(copy_jenkinsjob().version) print(copy_jenkinsjob(‘jun1‘))