Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,11 @@ private String buildTriggerUrl(String job, String securityToken, Collection<Stri
triggerUrlString += buildTokenRootUrl;
triggerUrlString += getBuildTypeUrl(isRemoteJobParameterized);

this.addToQueryString("job=" + this.encodeValue(job));
this.addToQueryString("job=" + this.encodeValue(job)); // works w/o generateJobPath()ing

} else {
triggerUrlString += "/job/";
triggerUrlString += this.encodeValue(job);
triggerUrlString += this.generateJobPath(job);
triggerUrlString += getBuildTypeUrl(isRemoteJobParameterized);
}

Expand Down Expand Up @@ -428,7 +428,7 @@ private String buildGetUrl(String job, String securityToken) {
String urlString = remoteServer.getAddress().toString();

urlString += "/job/";
urlString += this.encodeValue(job);
urlString += this.generateJobPath(job);

// don't try to include a security token in the URL if none is provided
if (!securityToken.equals("")) {
Expand Down Expand Up @@ -588,7 +588,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
BuildInfoExporterAction.addBuildInfoExporterAction(build, jobName, nextBuildNumber, Result.NOT_BUILT);

//Have to form the string ourselves, as we might not get a response from non-parameterized builds
String jobURL = remoteServerURL + "/job/" + this.encodeValue(jobName) + "/";
String jobURL = remoteServerURL + "/job/" + this.generateJobPath(jobName) + "/";

// This is only for Debug
// This output whether there is another job running on the remote host that this job had conflicted with.
Expand Down Expand Up @@ -1063,6 +1063,18 @@ private String encodeValue(String dirtyValue) {
return cleanValue;
}

/**
* Helper function for generating a job path
*/
private String generateJobPath(String jobName) {
String[] parts = jobName.split("/");
String[] encodedParts = new String[parts.length];
for (int i = 0; i < parts.length; i++) {
encodedParts[i] = this.encodeValue(parts[i]);
}
return StringUtils.join(encodedParts, "/job/");
}

// Getters
public String getRemoteJenkinsName() {
return this.remoteJenkinsName;
Expand Down Expand Up @@ -1158,7 +1170,7 @@ private boolean isRemoteJobParameterized(String jobName, AbstractBuild build, Bu
//build the proper URL to inspect the remote job
RemoteJenkinsServer remoteServer = this.findRemoteHost(this.getRemoteJenkinsName());
String remoteServerUrl = remoteServer.getAddress().toString();
remoteServerUrl += "/job/" + encodeValue(jobName);
remoteServerUrl += "/job/" + generateJobPath(jobName);
remoteServerUrl += "/api/json";

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;

public class RemoteBuildConfigurationTest {
@Rule
Expand Down Expand Up @@ -36,4 +37,33 @@ public void testRemoteBuild() throws Exception {

jenkinsRule.buildAndAssertSuccess(project);
}

@Test
public void testRemoteFolderedBuild() throws Exception {
jenkinsRule.jenkins.setCrumbIssuer(null);

JSONObject authenticationMode = new JSONObject();
authenticationMode.put("value", "none");
JSONObject auth = new JSONObject();
auth.put("authenticationMode", authenticationMode);

String remoteUrl = jenkinsRule.getURL().toString();
RemoteJenkinsServer remoteJenkinsServer =
new RemoteJenkinsServer(remoteUrl, "JENKINS", false, auth);
RemoteBuildConfiguration.DescriptorImpl descriptor =
jenkinsRule.jenkins.getDescriptorByType(RemoteBuildConfiguration.DescriptorImpl.class);
descriptor.setRemoteSites(remoteJenkinsServer);

MockFolder remoteJobFolder = jenkinsRule.createFolder("someJobFolder");
FreeStyleProject remoteProject = remoteJobFolder.createProject(FreeStyleProject.class, "someJobName");

FreeStyleProject project = jenkinsRule.createFreeStyleProject();

RemoteBuildConfiguration remoteBuildConfiguration = new RemoteBuildConfiguration(
remoteJenkinsServer.getDisplayName(), false, remoteProject.getFullName(), "",
"", true, null, null, false, true, 1);
project.getBuildersList().add(remoteBuildConfiguration);

jenkinsRule.buildAndAssertSuccess(project);
}
}