Skip to content

Commit

Permalink
[FIXED JENKINS-21525] Make command to run an external job work with f…
Browse files Browse the repository at this point in the history
…olders.
  • Loading branch information
jglick committed Jan 27, 2014
1 parent 18646cb commit c9d69d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 3 additions & 1 deletion changelog.html
Expand Up @@ -55,7 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
Using <code>java -jar jenkins-core.jar folder/external-monitor-job cmd …</code> did not work.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-21525">issue 21525</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
13 changes: 6 additions & 7 deletions core/src/main/java/hudson/Main.java
Expand Up @@ -37,7 +37,6 @@
import java.net.HttpRetryException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -104,14 +103,14 @@ public static int remotePost(String[] args) throws Exception {
}
}

String projectNameEnc = URLEncoder.encode(projectName,"UTF-8").replaceAll("\\+","%20");
URL jobURL = new URL(home + "job/" + Util.encode(projectName).replace("/", "/job/") + "/");

{// check if the job name is correct
HttpURLConnection con = open(new URL(home+"job/"+projectNameEnc+"/acceptBuildResult"));
HttpURLConnection con = open(new URL(jobURL, "acceptBuildResult"));
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if(con.getResponseCode()!=200) {
System.err.println(projectName+" is not a valid job name on "+home+" ("+con.getResponseMessage()+")");
System.err.println(jobURL + " is not a valid external job (" + con.getResponseCode() + " " + con.getResponseMessage() + ")");
return -1;
}
}
Expand Down Expand Up @@ -156,11 +155,11 @@ public static int remotePost(String[] args) throws Exception {
w.write("</log><result>"+ret+"</result><duration>"+(System.currentTimeMillis()-start)+"</duration></run>");
w.close();

String location = home+"job/"+projectNameEnc+"/postBuildResult";
URL location = new URL(jobURL, "postBuildResult");
while(true) {
try {
// start a remote connection
HttpURLConnection con = open(new URL(location));
HttpURLConnection con = open(location);
if (auth != null) con.setRequestProperty("Authorization", auth);
if (crumbField != null && crumbValue != null) {
con.setRequestProperty(crumbField, crumbValue);
Expand All @@ -182,7 +181,7 @@ public static int remotePost(String[] args) throws Exception {
} catch (HttpRetryException e) {
if(e.getLocation()!=null) {
// retry with the new location
location = e.getLocation();
location = new URL(e.getLocation());
continue;
}
// otherwise failed for reasons beyond us.
Expand Down

0 comments on commit c9d69d3

Please sign in to comment.