duancanjiu3754 2019-03-13 10:33
浏览 418

Jenkins API访问被拒绝

I'm trying to connect my WordPress website to my jobs Jenkins via the Jenkins API. Even if I saw a lot of posts and tried them I still don't manage to make my Jenkins API working.

So I have a Jenkins running in http://localhost:9090 with the job Test.

I configured the HTTP proxy of Jenkins at proxy:8080 with my username and password. When I validate the proxy in Jenkins, it's a success.

Jenkins tells me as well that my token was never used.

Now about my API, I have:

function getLastBuildStatus($url, $jobName, $username, $api_token){
    $password = 'xxxxx';
    $ch = initCurl($username, $api_token); //see function downside

    curl_setopt($ch, CURLOPT_URL, $url . '/job/' . $jobName . '/lastBuild/api/json');
    curl_setopt($ch, CURLOPT_PROXY, 'http://proxy:8080');
    curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); 

    $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;
}

With or without proxy I have an Access Denied error. Am I missing something?

Edit 1

I've add in the httpd.conf rules for the Jenkins proxy reverse. Still the same error but probably something to look deeper..

ProxyPass         /  http://localhost:9090/ nocanon
ProxyPassReverse  /  http://localhost:9090/
ProxyRequests     Off
AllowEncodedSlashes NoDecode
<Proxy http://localhost:9090/*>
  Order deny,allow
  Allow from all
</Proxy>

Edit 2

OK! So I could make it work via command line. When I enter that command, I can access the data:

curl  -v --noproxy localhost, http://localhost:9090/job/Test/api/json --user username:token

I don't get why because when I put curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false); in my PHP file, I still get the 403 error.

However, when I put curl_setopt($ch, CURLOPT_PROXY, '');, I get a Error:Failed to connect to localhost port 9090: Connection refused

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器