使用jenkins API时,在reconfig_job上失败 [英] While using jenkins API, getting a failure on reconfig_job

查看:667
本文介绍了使用jenkins API时,在reconfig_job上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using jenkins rest API to recurse through jobs and then reconfigure this one. All methods work except one. He's is my code :

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 '

It gets my configuration.xml, find the job as well but fails on server.reconfig_job('GithubMigration', config_xml) with the error , AttributeError: 'Jenkins' object has no attribute 'reconfig_job'

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

when obviously this functions exists in the jenkins rest API and yes I'm importing jenkins, from jenkinsapi.jenkins import Jenkins .

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

Edit 1 - I uninstalled Jenkinsapi and have only python-jenkins module and now it fails even before saying

AttributeError:模块"对象的行不具有属性"Jenkins":AttributeError:模块"对象的属性不具有"Jenkins"

AttributeError: 'module' object has no attribute 'Jenkins' for line : AttributeError: 'module' object has no attribute 'Jenkins'

有什么想法吗?

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

I tries solely python-jenkins API and tried their own example as you see here 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上出现属性错误的詹金斯-无模块.

Even this fails at jenkins.Jenkins with attribute error at Jenkins - No module.

我非常确定API已损坏.

I am pretty sure the API is broken.

推荐答案

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

Your script is probably importing wrong module. You can check it as follows:

import jenkins
print jenkins.__file__

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

If printed path is other than installation path of jenkins module (eg. C:\Python27_32\lib\site-packages\jenkins\__init__.pyc), then you should check pythonpath:

import sys
print sys.path

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

Common problem is existence of python script with same name as imported module in current directory, which is at the first place in search path ''.

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

For more info on import order see module search path

这篇关于使用jenkins API时,在reconfig_job上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆