Skip to content

Commit

Permalink
Fixed remote build url overriding for protocol and port
Browse files Browse the repository at this point in the history
  • Loading branch information
Declan Curran committed Feb 25, 2020
1 parent 7951c39 commit 38e2699
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -841,21 +841,9 @@ public RemoteBuildInfo updateBuildInfo(@Nonnull RemoteBuildInfo buildInfo, @Nonn
}
QueueItemData queueItem = getQueueItemData(queueId, context);
if (queueItem.isExecuted()) {
URL effectiveRemoteBuildURL = queueItem.getBuildURL();
try {
URI effectiveUri = new URI(context.effectiveRemoteServer.getAddress());
String effectiveHostname = effectiveUri.getHost();
URL remoteURL = queueItem.getBuildURL();
if (remoteURL != null) {
URI remoteUri = remoteURL.toURI();
String remoteHostname = remoteUri.getHost();
String effectiveRemoteAddress = remoteUri.toString().replaceAll(remoteHostname,
effectiveHostname);
effectiveRemoteBuildURL = new URL(effectiveRemoteAddress);
}
} catch (URISyntaxException ex) {
throw new AbortException(String.format("Unexpected syntax error: %s.", ex.toString()));
}
URL remoteBuildURL = queueItem.getBuildURL();
String effectiveRemoteServerAddress = context.effectiveRemoteServer.getAddress();
URL effectiveRemoteBuildURL = generateEffectiveRemoteBuildURL(remoteBuildURL, effectiveRemoteServerAddress);
buildInfo.setBuildData(queueItem.getBuildNumber(), effectiveRemoteBuildURL);
}
return buildInfo;
Expand All @@ -882,6 +870,24 @@ public RemoteBuildInfo updateBuildInfo(@Nonnull RemoteBuildInfo buildInfo, @Nonn
return buildInfo;
}

protected static URL generateEffectiveRemoteBuildURL(URL remoteBuildURL, String effectiveRemoteServerAddress) throws AbortException {
if (effectiveRemoteServerAddress == null || remoteBuildURL == null) {
return remoteBuildURL;
}

try {
URI effectiveUri = new URI(effectiveRemoteServerAddress);
return new URL(
effectiveUri.getScheme(),
effectiveUri.getHost(),
effectiveUri.getPort(),
remoteBuildURL.getPath()
);
} catch (URISyntaxException | MalformedURLException ex) {
throw new AbortException(String.format("Unexpected syntax error: %s.", ex.toString()));
}
}

private String printOffsetConsoleOutput(BuildContext context, String offset, RemoteBuildInfo buildInfo)
throws IOException, InterruptedException {
if (offset.equals("-1")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -453,6 +454,16 @@ public void testRemoveHashParameters() {
assertEquals("xxx", RemoteBuildConfiguration.removeHashParameters("xxx#zzz"));
}

@Test @WithoutJenkins
public void testGenerateEffectiveRemoteBuildURL() throws Exception {
URL remoteBuildURL = new URL("http://test:8080/job/Abc/3/");

assertEquals(new URL("https://foobar:8443/job/Abc/3/"), RemoteBuildConfiguration.generateEffectiveRemoteBuildURL(remoteBuildURL, "https://foobar:8443"));
assertEquals(new URL("http://foobar:8888/job/Abc/3/"), RemoteBuildConfiguration.generateEffectiveRemoteBuildURL(remoteBuildURL, "http://foobar:8888"));
assertEquals(new URL("https://foobar/job/Abc/3/"), RemoteBuildConfiguration.generateEffectiveRemoteBuildURL(remoteBuildURL, "https://foobar"));
assertEquals(new URL("http://foobar/job/Abc/3/"), RemoteBuildConfiguration.generateEffectiveRemoteBuildURL(remoteBuildURL, "http://foobar"));
}

@Test @WithoutJenkins
public void testGenerateJobUrl() throws MalformedURLException, AbortException {
RemoteJenkinsServer remoteServer = new RemoteJenkinsServer();
Expand Down

0 comments on commit 38e2699

Please sign in to comment.