python - 无法使用 jenkinsapi 在 Jenkins 中创建 View

标签 python jenkins jenkins-cli

我正在尝试使用 Python 和 jenkinsapi 在 Jenkins 中创建一堆嵌套 View 。

代码如下:

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>

我看到身份验证已通过, View 已创建,我被重定向 (HTTP 302) 到其配置页面,但因密码错误而失败。

执行后我可以看到新创建的 View ,再次运行脚本找到 View ,创建下一个 View 并再次失败并出现相同的错误。问题是我需要一打这样的 View 。

谁能帮我指出问题所在? 提前致谢。

最佳答案

如果您尝试创建嵌套 View ,但没有安装嵌套 View 插件,就会出现这种情况。也许这是你的问题?

关于python - 无法使用 jenkinsapi 在 Jenkins 中创建 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27815456/

相关文章:

python - 尝试在 python 中通过 TCP 创建粗略的发送/接收

python pep8缩进 Jenkins

Jenkins - 将构建日志从 master 复制到共享驱动器

ubuntu - Jenkins 抛出错误 : jenkins. model.InvalidBuildsDir: ${ITEM_ROOTDIR}/builds 不存在并且可能无法创建

jenkins - 多分支管道 Jenkins 作业与[ci跳过]

python - 我怎样才能得到 Sprite 在pygame中的位置坐标?

python - 如何将 Qt5 Tree 的引用返回到一组数据?

jenkins - 如何在 Gitlab Jenkins 中无需提交即可重建

python - 用gstreamer接收RTP流

jenkins - 如何在Jenkins管道脚本中访问参数?