使用jenkins API时,reconfig_job失败

Sco*_*oby 0 python python-2.7 python-3.x jenkins jenkins-cli

我正在使用jenkins rest API通过作业递归,然后重新配置这一作业。除一种方法外,所有方法均有效。他是我的代码:

def get_server_instance():
    jenkins_url = 'xxxx'
    #server = Jenkins(jenkins_url, username = '', password = '')
    # Connect to instance - username and password are optional
    server = jenkins.Jenkins(jenkins_url, username = '', password = '')
    return server


def get_job_details():
    # Refer Example #1 for definition of function 'get_server_instance'
    server = get_server_instance()
    for job in server.get_jobs_list():
        if job == "GithubMigration":
            configuration = server.get_job(job).get_config().encode('utf-8')
            #server.reconfig_job(job, configuration)
            if server.has_job("GithubMigration"):
                server.reconfig_job('GithubMigration', config_xml)
Run Code Online (Sandbox Code Playgroud)

它获取我的configuration.xml,也找到了工作,但在server.reconfig_job('GithubMigration',config_xml)上失败并显示错误AttributeError:'Jenkins'对象没有属性'reconfig_job'

当显然此功能存在于jenkins rest API中并且是的时候,我正在从jenkinsapi.jenkins import Jenkins导入jenkins。

编辑1-我卸载了Jenkinsapi,只有python-jenkins模块,现在即使在说之前它也失败了

AttributeError:'module'对象没有属性'Jenkins'到行:AttributeError:'module'对象没有属性'Jenkins'

有任何想法吗?

编辑2:

我只尝试使用python-jenkins API并尝试了自己的示例,如您在此处看到的http://python-jenkins.readthedocs.org/en/latest/example.html

import jenkins
j = jenkins.Jenkins('http://your_url_here', 'username', 'password')
j.get_jobs()
j.create_job('empty', jenkins.EMPTY_CONFIG_XML)
j.disable_job('empty')
j.copy_job('empty', 'empty_copy')
j.enable_job('empty_copy')
j.reconfig_job('empty_copy', jenkins.RECONFIG_XML)
Run Code Online (Sandbox Code Playgroud)

甚至在jenkins上也失败了.Jenkins在Jenkins发生属性错误-没有模块。

我很确定API已损坏。

Che*_*mik 5

您的脚本可能正在导入错误的模块。您可以按以下方式检查它:

import jenkins
print jenkins.__file__
Run Code Online (Sandbox Code Playgroud)

如果打印路径不是jenkins模块的安装路径(例如C:\Python27_32\lib\site-packages\jenkins\__init__.pyc),则应检查pythonpath:

import sys
print sys.path
Run Code Online (Sandbox Code Playgroud)

常见问题是存在与当前目录中导入模块名称相同的python脚本,该脚本位于搜索路径中的第一位''

有关导入顺序的更多信息,请参见模块搜索路径