From 86bf6b7603c5c51c8ffc34fe1e78698fa9d03d3e Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 21 Apr 2015 08:25:53 -0700 Subject: [PATCH] Allow the advertised TCP slave agent port number to be modified. This allows TCP slave agent port to be reverse proxied. --- changelog.html | 2 ++ core/src/main/java/hudson/Functions.java | 7 ++++--- core/src/main/java/hudson/TcpSlaveAgentListener.java | 12 ++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/changelog.html b/changelog.html index ab763a42a0..8c01918299 100644 --- a/changelog.html +++ b/changelog.html @@ -58,6 +58,8 @@ Upcoming changes
  • Search box did not work well inside folders. (issue 24433) +
  • + Advertised TCP slave agent port number is made tweakable.

    What's new in 1.610 (2015/04/19)

    diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 6c4377652a..c6f473be4f 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -1887,9 +1887,10 @@ public class Functions { TcpSlaveAgentListener tal = j.tcpSlaveAgentListener; if (tal !=null) { - rsp.setIntHeader("X-Hudson-CLI-Port", tal.getPort()); - rsp.setIntHeader("X-Jenkins-CLI-Port", tal.getPort()); - rsp.setIntHeader("X-Jenkins-CLI2-Port", tal.getPort()); + int p = TcpSlaveAgentListener.CLI_PORT !=null ? TcpSlaveAgentListener.CLI_PORT : tal.getPort(); + rsp.setIntHeader("X-Hudson-CLI-Port", p); + rsp.setIntHeader("X-Jenkins-CLI-Port", p); + rsp.setIntHeader("X-Jenkins-CLI2-Port", p); rsp.setHeader("X-Jenkins-CLI-Host", TcpSlaveAgentListener.CLI_HOST_NAME); } } diff --git a/core/src/main/java/hudson/TcpSlaveAgentListener.java b/core/src/main/java/hudson/TcpSlaveAgentListener.java index 059e2af965..46d99076ae 100644 --- a/core/src/main/java/hudson/TcpSlaveAgentListener.java +++ b/core/src/main/java/hudson/TcpSlaveAgentListener.java @@ -204,6 +204,18 @@ public final class TcpSlaveAgentListener extends Thread { * TODO: think about how to expose this (including whether this needs to be exposed at all.) */ public static String CLI_HOST_NAME = System.getProperty(TcpSlaveAgentListener.class.getName()+".hostName"); + + /** + * Port number that we advertise the CLI client to connect to. + * This is primarily for the case where the port that Jenkins runs is different from the port + * that external world should connect to, because of the presence of NAT / port-forwarding / TCP reverse + * proxy. + * + * If left to null, fall back to {@link #getPort()} + * + * @since 1.611 + */ + public static Integer CLI_PORT = Integer.getInteger(TcpSlaveAgentListener.class.getName()+".port"); } /* -- GitLab