jenkins 出现“Error 403 No valid crumb was included in the request ”的解决方案

背景介绍

开发的jenkins job 在local的 一台windows 上,而我们测试的jenkins job 在azure 上的一台windows server 2012 上。由于 azure上机器的网络比local的网络好,所以测试不愿意把测试job建在开发的jenkins上,开发也觉得迁移自己的job到azure上麻烦。那我们只能使用Remote access API(https://wiki.jenkins.io/display/JENKINS/Remote+access+API) ,来让开发的job 主动来触发在azure的测试job。

使用如下命令来让local 的jenkins job 去主动触发 azure上测试的jenkins job

curl -X POST http://168.192.10.78:8080/job/AndroidTestCase/build --user xiaohua:3a2522f75356f6791f6040bf9ee3808b 

执行后在jenkins出现如下错误:

<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</h2>
<p>Problem accessing /job/AndroidTestCase/build. Reason:
<pre>    No valid crumb was included in the request</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

解决方案:
在jenkins 的Configure Global Security下 , 取消“防止跨站点请求伪造(Prevent Cross Site Request Forgery exploits)”的勾选。(如下图)这里写图片描述

发布了56 篇原创文章 · 获赞 101 · 访问量 27万+
展开阅读全文

Jenkins API - 连接被拒绝或错误403

03-14

<div class="post-text" itemprop="text"> <p>I'm trying to manage Jenkins' jobs via an API. By command line, I have no problem accessing data with this line:</p> <p><code>curl -v --noproxy localhost, http://localhost:4545/job/Test/api/json --user username:token</code></p> <p>(Jenkins is running at <code>localhost:4545</code>). The <code>--noproxy</code> part is important, otherwise I have a <code>403 error</code>. </p> <p>When I try to do the same in my PHP files, it's not working.. </p> <p>Here my API code:</p> <pre><code>function getLastBuildStatus($url, $jobName, $username, $api_token){ $ch = initCurl($username, $api_token); //see function downside curl_setopt($ch, CURLOPT_URL, $url . '/job/' . $jobName . '/lastBuild/api/json'); curl_setopt($ch, CURLOPT_NOPROXY, "localhost"); //return Error:Failed to connect to localhost port 4545: Connection refused curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true); //return Error 403 Access denied $result = executeCurl($ch); $json = json_decode($result); var_dump ($result); if($json){ return $json->result; } else { return -1; } function initCurl($username, $api_token){ $ch = curl_init(); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, false ); curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $api_token); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); return $ch; } </code></pre> <p>I tried as well to set the proxy but I get an <code>error 403 forbidden</code> as well. </p> </div> 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览