First off, thanks for putting this module together. It saved me some time in putting together a proof of concept.

I'm calling jenkins_request() in my module to start a build, passing it a few parameters in the $query array. The build works fine, but I'm wondering how to view the response from jenkins. For instance, the below returns NULL for me. Thanks!

var_dump(jenkins_request($path, $query, $method = 'POST'));

Comments

vinmassaro’s picture

Status: Needs review » Active

Upon further inspection, jenkins_request tries to return json decoded data:

return in_array($response->code, range(200, 202)) ? drupal_json_decode($response->data) : FALSE;

Our Jenkins instance was not returning JSON in $response->data. I was getting a string returned with HTML from our single-sign on authentication in front of Jenkins. We have CAS SSO in front of Jenkins but can buildWithParameters using basic authentication. I will submit a patch to return the response code and data in this case.

vinmassaro’s picture

Status: Active » Needs review
StatusFileSize
new827 bytes

Is there any reason to not just return the whole response object? Here's a patch that does that. This allows me to correctly check if I received a response.

skwashd’s picture

Status: Active » Needs review

I will looking into this. All of our internal wrapper code assume decode json objects to be returned on success.

vinmassaro’s picture

That's fair. I suppose our instance should be returning JSON instead of the SSO login page. I'll ask our Jenkins guys to look into this and file a bug if needed.

vinmassaro’s picture

I finally figured out the problem. Two things:

1. I was not setting headers in jenkins_request() to set as JSON
2. We are running a slightly outdated version of Jenkins. JSON response was implemented in JENKINS-13546 and released in Jenkins 1.463 (2012/05/07).

This is how I'm doing it in #1:
jenkins_request($path, $query, $method = 'POST', NULL, $headers = array('Content-Type' => 'application/json', 'Accept' => 'application/json')

Is there a better way? Thanks.

skwashd’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Status: Needs review » Fixed

You can now access the response via the $response parameter for jenkins_request() which is passed by reference - yes this is a BC breaking API change. See the commit for more details.

I plan to release 7.x-1.0-beta3 over the weekend.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.