使用jenkins API时,在reconfig_job上出现故障

问题描述 投票:0回答:1

我正在使用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)

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

显然这个函数存在于jenkins rest API中,是的,我正在导入jenkins,来自jenkinsapi.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)

甚至连Jenkins的jenkins.Jenkins都没有属性错误 - 没有模块。

我很确定API已被破坏。

python python-2.7 python-3.x jenkins jenkins-cli
1个回答
4
投票

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

import jenkins
print jenkins.__file__

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

import sys
print sys.path

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

有关导入订单的更多信息,请参阅module search path

© www.soinside.com 2019 - 2024. All rights reserved.