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

Commit

Permalink
enabling support for "Build Token Root "
Browse files Browse the repository at this point in the history
“build token root” support is controled as a remote-host level (not job
by job)
  • Loading branch information
morficus committed Nov 29, 2013
1 parent e73e354 commit f687dbe
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -36,7 +38,6 @@ public class RemoteBuildConfiguration extends Builder {
private final String token;
private final String remoteJenkinsName;
private final String job;
private final boolean buildTokenRootEnabled;
// "parameters" is the raw string entered by the user
private final String parameters;
// "parameterList" is the cleaned-up version of "parameters" (stripped out comments, character encoding, etc)
Expand All @@ -56,7 +57,6 @@ public RemoteBuildConfiguration(String remoteSites, String job, String token, St
this.remoteJenkinsName = remoteSites;
this.parameters = parameters;
this.job = job.trim();
this.buildTokenRootEnabled = false;

// split the parameter-string into an array based on the new-line character
String[] params = parameters.split("\n");
Expand Down Expand Up @@ -165,10 +165,11 @@ private void addToQueryString(String item) {
}

private String buildTriggerUrl() {
String triggerUrlString = this.findRemoteHost(this.getRemoteJenkinsName()).getAddress().toString();
RemoteJenkinsServer remoteServer = this.findRemoteHost(this.getRemoteJenkinsName());

if (this.getbuildTokenRootEnabled()) {
// if (true) {
String triggerUrlString = remoteServer.getAddress().toString();

if (remoteServer.getHasBuildTokenRootSupport()) {
triggerUrlString += buildTokenRootUrl;
triggerUrlString += paramerizedBuildUrl;

Expand All @@ -186,6 +187,8 @@ private String buildTriggerUrl() {

this.addToQueryString(this.getParameters(true));

this.addToQueryString("delay=0");

triggerUrlString += "?" + this.getQueryString();

return triggerUrlString;
Expand Down Expand Up @@ -221,21 +224,21 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
// - http://jenkins.local/job/test/lastBuild/api/json

InputStream is = connection.getInputStream();
/*

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

while ((line = rd.readLine()) != null) {
System.out.println(line);
}
rd.close();
*/
//while ((line = rd.readLine()) != null) {
//System.out.println(line); //JSONObject r = new

//}
//rd.close();

} catch (IOException e) {
// something failed with the connection, so throw an exception to mark the build as failed.
e.printStackTrace();
throw new AbortException("Faield to oppen conenction to the remote server.");
throw new AbortException(e.getMessage());

This comment has been minimized.

Copy link
@daniel-beck

daniel-beck Nov 30, 2013

An option to make this build step 'optional' (i.e. don't fail the build if this step fails) would be great.

This comment has been minimized.

Copy link
@morficus

morficus Nov 30, 2013

Author Owner

implemented.
check out the updated screenshots to see what it looks like.

} finally {
// always make sure we close the connection
if (connection != null) {
Expand Down Expand Up @@ -275,10 +278,6 @@ public String getParameters() {
return this.parameters;
}

public boolean getbuildTokenRootEnabled() {
return this.buildTokenRootEnabled;
}

public String getQueryString() {
return this.queryString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ public class RemoteJenkinsServer extends AbstractDescribableImpl<RemoteJenkinsSe

private final URL address;
private final String displayName;
private final boolean hasBuildTokenRootSupport;

@DataBoundConstructor
public RemoteJenkinsServer(String address, String displayName) throws MalformedURLException {
public RemoteJenkinsServer(String address, String displayName, boolean hasBuildTokenRootSupport) throws MalformedURLException {

this.address = new URL(address);
this.displayName = displayName;
this.hasBuildTokenRootSupport = hasBuildTokenRootSupport;

}

Expand All @@ -50,6 +52,10 @@ public URL getAddress() {
return address;
}

public boolean getHasBuildTokenRootSupport() {
return this.hasBuildTokenRootSupport;
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<f:entry title="Select a remote host" >
<f:select field="remoteSites" />
</f:entry>

<f:entry title="Remote Job Name" field="job">
<f:textbox />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<f:entry title="Display name" field="displayName" >
<f:textbox />
</f:entry>


<f:entry title="Enable 'build token root' support" field="hasBuildTokenRootSupport">
<f:checkbox />
</f:entry>

<f:entry title="Remote address and port" field="address" >
<f:textbox />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div>
<div style="font-weight: bolder; text-decoration: underline">
Build Token Root
</div>
If your remote Jenkins host has the
<a href="https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin" target="_blank">
"Build Token Root" plugin"
</a>
installed, then you will want to enable this option.
</div>

0 comments on commit f687dbe

Please sign in to comment.