If you use the Python 2.7.12,jenkins version for Jenkins ver. 2.22, you can perform a job copy of Jenkins by using the following code of the modifications I mentioned above
Http://www.cnblogs.com/chongyou/p/8414334.html
But if you have a Python version of 2.7.5,jenkins version for Jenkins ver. 2.73.1, or an issue jenkinsapi.custom_exceptions using API errors. Jenkinsapiexception, use the following code to
From __future__ import print_functionfrom jenkinsapi.jenkins import Jenkinsfrom jenkinsapi.utils.crumb_requester Import crumbrequesterimport sysreload (SYS) sys.setdefaultencoding (' utf8 ') jenkins_url = ' domain name/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 '))
Use the command to create a job for Jenkins and resolve the jenkinsapi.custom_exceptions. Jenkinsapiexception Error