Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
)
  • Loading branch information
morficus committed Apr 7, 2014
1 parent df3cee2 commit 0f704da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,9 @@
###Bug fixes: ###Bug fixes:
- fixing [JENKINS-22325](https://issues.jenkins-ci.org/browse/JENKINS-22325) - local job fails when not sending any parameters to remote job - fixing [JENKINS-22325](https://issues.jenkins-ci.org/browse/JENKINS-22325) - local job fails when not sending any parameters to remote job
- fixing [JENKINS-21470](https://issues.jenkins-ci.org/browse/JENKINS-21470) - UI does not display that a build is using a file to get the parameter list - fixing [JENKINS-21470](https://issues.jenkins-ci.org/browse/JENKINS-21470) - UI does not display that a build is using a file to get the parameter list
- fixing [JENKINS-22493](https://issues.jenkins-ci.org/browse/JENKINS-22493) - 400 when remote job has default parameters and parameters are not explicitly list them. - fixing [JENKINS-22493](https://issues.jenkins-ci.org/browse/JENKINS-22493) - 400 when remote job has default parameters and parameters are not explicitly list them
- fixing [JENKINS-22427](https://issues.jenkins-ci.org/browse/JENKINS-22427) - fails when remote job waits for available executor



#2.1 (Feb 17th, 2014) #2.1 (Feb 17th, 2014)
###New Feature/Enhancement: ###New Feature/Enhancement:
Expand Down
Expand Up @@ -440,7 +440,7 @@ private String buildGetUrl(String job, String securityToken) {
* @throws IOException * @throws IOException
*/ */
private void failBuild(Exception e, BuildListener listener) throws IOException { private void failBuild(Exception e, BuildListener listener) throws IOException {
e.getStackTrace(); System.out.print(e.getStackTrace());
if (this.getShouldNotFailBuild()) { if (this.getShouldNotFailBuild()) {
listener.error("Remote build failed for the following reason, but the build will continue:"); listener.error("Remote build failed for the following reason, but the build will continue:");
listener.error(e.getMessage()); listener.error(e.getMessage());
Expand Down Expand Up @@ -667,7 +667,6 @@ public JSONObject sendHTTPCall(String urlString, String requestType, AbstractBui


JSONObject responseObject = null; JSONObject responseObject = null;


try {
URL buildUrl = new URL(urlString); URL buildUrl = new URL(urlString);
connection = (HttpURLConnection) buildUrl.openConnection(); connection = (HttpURLConnection) buildUrl.openConnection();


Expand All @@ -683,31 +682,37 @@ public JSONObject sendHTTPCall(String urlString, String requestType, AbstractBui


if (!usernameTokenConcat.equals(":")) { if (!usernameTokenConcat.equals(":")) {
// token-macro replacment // token-macro replacment
usernameTokenConcat = TokenMacro.expandAll(build, listener, usernameTokenConcat); try {
usernameTokenConcat = TokenMacro.expandAll(build, listener, usernameTokenConcat);
} catch (MacroEvaluationException e) {
this.failBuild(e, listener);
} catch (InterruptedException e) {
this.failBuild(e, listener);
}


byte[] encodedAuthKey = Base64.encodeBase64(usernameTokenConcat.getBytes()); byte[] encodedAuthKey = Base64.encodeBase64(usernameTokenConcat.getBytes());
connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthKey)); connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthKey));
} }

try {
connection.setDoInput(true); connection.setDoInput(true);
connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Accept", "application/json");
connection.setRequestMethod(requestType); connection.setRequestMethod(requestType);
// wait up to 5 seconds for the connection to be open // wait up to 5 seconds for the connection to be open
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
connection.connect(); connection.connect();

InputStream is = connection.getInputStream(); InputStream is = connection.getInputStream();

BufferedReader rd = new BufferedReader(new InputStreamReader(is)); BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line; String line;
// String response = ""; // String response = "";
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();

while ((line = rd.readLine()) != null) { while ((line = rd.readLine()) != null) {
response.append(line); response.append(line);
} }
rd.close(); rd.close();

// JSONSerializer serializer = new JSONSerializer(); // JSONSerializer serializer = new JSONSerializer();
// need to parse the data we get back into struct // need to parse the data we get back into struct
//listener.getLogger().println("Called URL: '" + urlString + "', got response: '" + response.toString() + "'"); //listener.getLogger().println("Called URL: '" + urlString + "', got response: '" + response.toString() + "'");
Expand All @@ -724,12 +729,16 @@ public JSONObject sendHTTPCall(String urlString, String requestType, AbstractBui
} }


} catch (IOException e) { } catch (IOException e) {
// something failed with the connection, so throw an exception to mark the build as failed. //If we get a 404 when trying to check a builds status (aka: called from "getBuildStatus") it just means that the build hasn't been queued up because there aren't any more executors available to call the remote server.
this.failBuild(e, listener); //So we basically pretend like the error didn't happen.
} catch (MacroEvaluationException e) { String callingMethod = Thread.currentThread().getStackTrace()[2].getMethodName();
this.failBuild(e, listener); if(connection.getResponseCode() == 404 && callingMethod == "getBuildStatus"){
} catch (InterruptedException e) { return null;
this.failBuild(e, listener); }else{
//something failed with the connection, so throw an exception to mark the build as failed.
this.failBuild(e, listener);
}

} finally { } finally {
// always make sure we close the connection // always make sure we close the connection
if (connection != null) { if (connection != null) {
Expand Down

0 comments on commit 0f704da

Please sign in to comment.