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