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

Commit f687dbe

Browse files
committed
enabling support for "Build Token Root "
“build token root” support is controled as a remote-host level (not job by job)
1 parent e73e354 commit f687dbe

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import org.kohsuke.stapler.DataBoundConstructor;
1717
import org.kohsuke.stapler.StaplerRequest;
1818

19+
import java.io.BufferedReader;
1920
import java.io.IOException;
2021
import java.io.InputStream;
22+
import java.io.InputStreamReader;
2123
import java.net.HttpURLConnection;
2224
import java.net.MalformedURLException;
2325
import java.net.URL;
@@ -36,7 +38,6 @@ public class RemoteBuildConfiguration extends Builder {
3638
private final String token;
3739
private final String remoteJenkinsName;
3840
private final String job;
39-
private final boolean buildTokenRootEnabled;
4041
// "parameters" is the raw string entered by the user
4142
private final String parameters;
4243
// "parameterList" is the cleaned-up version of "parameters" (stripped out comments, character encoding, etc)
@@ -56,7 +57,6 @@ public RemoteBuildConfiguration(String remoteSites, String job, String token, St
5657
this.remoteJenkinsName = remoteSites;
5758
this.parameters = parameters;
5859
this.job = job.trim();
59-
this.buildTokenRootEnabled = false;
6060

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

167167
private String buildTriggerUrl() {
168-
String triggerUrlString = this.findRemoteHost(this.getRemoteJenkinsName()).getAddress().toString();
168+
RemoteJenkinsServer remoteServer = this.findRemoteHost(this.getRemoteJenkinsName());
169169

170-
if (this.getbuildTokenRootEnabled()) {
171-
// if (true) {
170+
String triggerUrlString = remoteServer.getAddress().toString();
171+
172+
if (remoteServer.getHasBuildTokenRootSupport()) {
172173
triggerUrlString += buildTokenRootUrl;
173174
triggerUrlString += paramerizedBuildUrl;
174175

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

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

190+
this.addToQueryString("delay=0");
191+
189192
triggerUrlString += "?" + this.getQueryString();
190193

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

223226
InputStream is = connection.getInputStream();
224-
/*
227+
225228
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
226-
String line;
227-
StringBuffer response = new StringBuffer();
229+
//String line;
230+
//StringBuffer response = new StringBuffer();
228231

229-
while ((line = rd.readLine()) != null) {
230-
System.out.println(line);
231-
}
232-
rd.close();
233-
*/
232+
//while ((line = rd.readLine()) != null) {
233+
//System.out.println(line); //JSONObject r = new
234+
235+
//}
236+
//rd.close();
234237

235238
} catch (IOException e) {
236239
// something failed with the connection, so throw an exception to mark the build as failed.
237240
e.printStackTrace();
238-
throw new AbortException("Faield to oppen conenction to the remote server.");
241+
throw new AbortException(e.getMessage());
239242
} finally {
240243
// always make sure we close the connection
241244
if (connection != null) {
@@ -275,10 +278,6 @@ public String getParameters() {
275278
return this.parameters;
276279
}
277280

278-
public boolean getbuildTokenRootEnabled() {
279-
return this.buildTokenRootEnabled;
280-
}
281-
282281
public String getQueryString() {
283282
return this.queryString;
284283
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ public class RemoteJenkinsServer extends AbstractDescribableImpl<RemoteJenkinsSe
2525

2626
private final URL address;
2727
private final String displayName;
28+
private final boolean hasBuildTokenRootSupport;
2829

2930
@DataBoundConstructor
30-
public RemoteJenkinsServer(String address, String displayName) throws MalformedURLException {
31+
public RemoteJenkinsServer(String address, String displayName, boolean hasBuildTokenRootSupport) throws MalformedURLException {
3132

3233
this.address = new URL(address);
3334
this.displayName = displayName;
35+
this.hasBuildTokenRootSupport = hasBuildTokenRootSupport;
3436

3537
}
3638

@@ -50,6 +52,10 @@ public URL getAddress() {
5052
return address;
5153
}
5254

55+
public boolean getHasBuildTokenRootSupport() {
56+
return this.hasBuildTokenRootSupport;
57+
}
58+
5359
@Override
5460
public DescriptorImpl getDescriptor() {
5561
return (DescriptorImpl) super.getDescriptor();

src/main/resources/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration/config.jelly

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<f:entry title="Select a remote host" >
33
<f:select field="remoteSites" />
44
</f:entry>
5-
65
<f:entry title="Remote Job Name" field="job">
76
<f:textbox />
87
</f:entry>

src/main/resources/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteJenkinsServer/config.jelly

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
<f:entry title="Display name" field="displayName" >
33
<f:textbox />
44
</f:entry>
5-
5+
6+
<f:entry title="Enable 'build token root' support" field="hasBuildTokenRootSupport">
7+
<f:checkbox />
8+
</f:entry>
9+
610
<f:entry title="Remote address and port" field="address" >
711
<f:textbox />
812
</f:entry>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div>
2+
<div style="font-weight: bolder; text-decoration: underline">
3+
Build Token Root
4+
</div>
5+
If your remote Jenkins host has the
6+
<a href="https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin" target="_blank">
7+
"Build Token Root" plugin"
8+
</a>
9+
installed, then you will want to enable this option.
10+
</div>

0 commit comments

Comments
 (0)