我试图使用Python和jenkinsapi在Jenkins中创建一堆嵌套视图。
代码如下:
jenkins_url = "http://127.0.0.1:8080/"
api = Jenkins(jenkins_url, 'jenkins_admin', 'jenkins_password')
logger.info('view_name is %s' %view_name)
new_view = api.views.create(view_name, Views.NESTED_VIEW)
如果我禁用授权并允许“任何人都可以做任何事情”,那么一切顺利。但无法通过用户/密码验证。我们使用的是Active Directory,用户具有管理权限。
失败的是:
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1
DEBUG:requests.packages.urllib3.connectionpool:"GET /api/python **HTTP/1.1" 200 3290**
INFO:root: view_name is 9.8
INFO:jenkinsapi.views:Creating "hudson.plugins.nested_view.NestedView" view "9.8"
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1
DEBUG:requests.packages.urllib3.connectionpool:"POST /createView **HTTP/1.1" 302 0**
DEBUG:requests.packages.urllib3.connectionpool:"GET /view/9.8/configure **HTTP/1.1" 401 1445**
Traceback (most recent call last):
File "JenkinsNewVersionJobsItems.py", line 46, in <module>
top_view = NewVersionJobsItemsUtils.createView(short_version, api, NESTED)
File "/tmp/NewVersionJobsItemsUtils.py", line 35, in createView
new_view = parent_view.views.create(view_name, Views.NESTED_VIEW)
File "build/bdist.linux-x86_64/egg/jenkinsapi/views.py", line 103, in create
File "build/bdist.linux-x86_64/egg/jenkinsapi/utils/requester.py", line 117, in post_and_confirm_status
jenkinsapi.custom_exceptions.JenkinsAPIException: Operation failed. url=http://127.0.0.1/view/9.8/configure, data={'json': '{"name": "9.8", "mode": "hudson.plugins.nested_view.NestedView"}', 'name': '9.8', 'Submit': 'OK', 'mode': 'hudson.plugins.nested_view.NestedView'}, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=401, text=<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>**Error 401 Invalid password/token for user: jenkins**</title>
</head>
<body><h2>HTTP ERROR 401</h2>
我看到身份验证已通过,视图已创建,我被重定向(HTTP 302)到其配置页面,而不是密码错误错误。
执行后我可以看到新创建的视图,再次运行脚本找到视图,创建下一个视图并再次失败并出现相同的错误。问题是我需要十几个这样的观点。
有人能帮忙或指出我的问题吗? 提前谢谢。
答案 0 :(得分:1)
如果您尝试创建嵌套视图但未安装嵌套视图插件,则会出现这种情况。也许这是你的问题?