jenkins api打包

jenkins python-API打包问题

jenkins Error 403 异常

安装新版本jenkins,想使用代码调用api打包,但是确发生如下403异常:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 403 No valid crumb was included in the request</title>
</head>
<body><h2>HTTP ERROR 403 No valid crumb was included in the request</h2>
<table>
<tr><th>URI:</th><td>/job/%E6%B5%8B%E8%AF%95/build</td></tr>
<tr><th>STATUS:</th><td>403</td></tr>
<tr><th>MESSAGE:</th><td>No valid crumb was included in the request</td></tr>
<tr><th>SERVLET:</th><td>Stapler</td></tr>
</table>
<hr><a href="https://eclipse.org/jetty">Powered by Jetty:// 9.4.38.v20210224</a><hr/>

</body>
</html>

这个问题查了好久,有版本说是跨站请求保护,但是新版本的jenkins(2.204.6之后)就没有这个按钮了,默认就是启用的;在一个文章中查到在启动jenkins的时候可以添加参数禁用csrf的功能;文章连接→禁用csrf
也就是在jenkins启动的时候,加入如下参数:
-Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true
我是用war启动的,但是即便加入了这个参数还是不行;没有找到究竟怎么解决,在官网看到了对应python封装包,好吧最终成功解决了这个问题。

python-jenkins

python-jenkins的官网连接
在使用ipython测试的时候,成功传入了参数,build成功。
安装包可以直接使用pip安装即可: pip install python-jenkins
一个简单的实例:

In [1]: import jenkins

In [2]: server = jenkins.Jenkins('http://host:7799', username='admin',password='123456')
In [36]: p1           # 参数的形式{key:value,},可以根据实际应用传参
Out[36]: 
{'branch': 'develop',
 'map_uuid_name': 'xxxxx',
 'modules': 'xxx',
 'release': '35',
 'version': '3.0.0'}

In [37]: resp = server.build_job(u"测试", parameters=p1)

In [38]: resp
Out[38]: 11

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值