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'));
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 0001-return-full-response-object-in-jenkins_request.patch | 827 bytes | vinmassaro |
Comments
Comment #1
vinmassaro commentedUpon further inspection,
jenkins_requesttries to return json decoded data: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.
Comment #2
vinmassaro commentedIs 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.
Comment #3
skwashd commentedI will looking into this. All of our internal wrapper code assume decode json objects to be returned on success.
Comment #4
vinmassaro commentedThat'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.
Comment #5
vinmassaro commentedI finally figured out the problem. Two things:
1. I was not setting headers in
jenkins_request()to set as JSON2. 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.
Comment #6
skwashd commentedYou 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.