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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题