Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

Commit df3cee2

Browse files
committed
improving the error-checking when receiving a response from the remote build server
1 parent d544e32 commit df3cee2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/java/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package org.jenkinsci.plugins.ParameterizedRemoteTrigger;
22

33
import hudson.AbortException;
4-
54
import hudson.FilePath;
6-
75
import hudson.EnvVars;
8-
96
import hudson.Launcher;
107
import hudson.Extension;
118
import hudson.util.CopyOnWriteList;
@@ -21,6 +18,8 @@
2118
//import net.sf.json.
2219
//import net.sf.json.
2320

21+
import net.sf.json.util.JSONUtils;
22+
2423
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
2524
import org.apache.commons.lang.StringUtils;
2625
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
@@ -712,8 +711,13 @@ public JSONObject sendHTTPCall(String urlString, String requestType, AbstractBui
712711
// JSONSerializer serializer = new JSONSerializer();
713712
// need to parse the data we get back into struct
714713
//listener.getLogger().println("Called URL: '" + urlString + "', got response: '" + response.toString() + "'");
715-
if ( response.toString().isEmpty() ) {
716-
listener.getLogger().println("Remote Jenkins server returned empty response to trigger.");
714+
715+
//Solving issue reported in this comment: https://github.com/jenkinsci/parameterized-remote-trigger-plugin/pull/3#issuecomment-39369194
716+
//Seems like in Jenkins version 1.547, when using "/build" (job API for non-parameterized jobs), it returns a string indicating the status.
717+
//But in newer versions of Jenkins, it just returns an empty response.
718+
//So we need to compensate and check for both.
719+
if ( JSONUtils.mayBeJSON(response.toString()) == false) {
720+
listener.getLogger().println("Remote Jenkins server returned empty response or invalid JSON - but we can still proceed with the remote build.");
717721
return null;
718722
} else {
719723
responseObject = (JSONObject) JSONSerializer.toJSON(response.toString());

0 commit comments

Comments
 (0)