Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-52204] - Skip port availability check when -tunnel option is set #279

Merged
merged 2 commits into from
Jun 29, 2018
Merged
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
9 changes: 7 additions & 2 deletions src/main/java/hudson/remoting/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ public Thread newThread(final Runnable r) {
private String proxyCredentials = System.getProperty("proxyCredentials");

/**
* See Main#tunnel in the jnlp-agent module for the details.
* See {@link hudson.remoting.jnlp.Main#tunnel} for the documentation.
*/
@CheckForNull
private String tunnel;

private boolean disableHttpsCertValidation;
Expand Down Expand Up @@ -305,7 +306,11 @@ public URL getHudsonUrl() {
return hudsonUrl;
}

public void setTunnel(String tunnel) {
/**
* If set, connect to the specified host and port instead of connecting directly to Jenkins.
* @param tunnel Value. {@code null} to disable tunneling
*/
public void setTunnel(@CheckForNull String tunnel) {
this.tunnel = tunnel;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/remoting/jnlp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class Main {

@Option(name="-tunnel",metaVar="HOST:PORT",
usage="Connect to the specified host and port, instead of connecting directly to Jenkins. " +
"Useful when connection to Hudson needs to be tunneled. Can be also HOST: or :PORT, " +
"Useful when connection to Jenkins needs to be tunneled. Can be also HOST: or :PORT, " +
"in which case the missing portion will be auto-configured like the default behavior")
public String tunnel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ public void setProxyCredentials(String user, String pass) {
this.proxyCredentials = user + ":" + pass;
}

@CheckForNull
public String getTunnel() {
return tunnel;
}

public void setTunnel(String tunnel) {
public void setTunnel(@CheckForNull String tunnel) {
this.tunnel = tunnel;
}

Expand Down Expand Up @@ -280,10 +281,17 @@ public JnlpAgentEndpoint resolve() throws IOException {
firstError = chain(firstError, new IOException(jenkinsUrl + " is publishing an invalid port"));
continue;
}
if (!isPortVisible(host, port, 5000)) {
firstError = chain(firstError, new IOException(jenkinsUrl + " provided port:" + port
+ " is not reachable"));
continue;
if (tunnel == null) {
if (!isPortVisible(host, port, 5000)) {
firstError = chain(firstError, new IOException(jenkinsUrl + " provided port:" + port
+ " is not reachable"));
continue;
} else {
LOGGER.log(Level.FINE, "TCP Agent Listener Port availability check passed");
}
} else {
LOGGER.log(Level.INFO, "Remoting TCP connection tunneling is enabled. " +
"Skipping the TCP Agent Listener Port availability check");
}
// sort the URLs so that the winner is the one we try first next time
final String winningJenkinsUrl = jenkinsUrl;
Expand All @@ -306,6 +314,8 @@ public int compare(String o1, String o2) {
if (tokens[0].length() > 0) host = tokens[0];
if (tokens[1].length() > 0) port = Integer.parseInt(tokens[1]);
}

//TODO: all the checks above do not make much sense if tunneling is enabled (JENKINS-52246)

return new JnlpAgentEndpoint(host, port, identity, agentProtocolNames, selectedJenkinsURL);
} finally {
Expand Down