From f8531f4f53f8cd6814d0c010dfdd15c9892bb997 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 29 Aug 2024 17:19:33 -0400 Subject: [PATCH] Decouple `InboundAgentRule.Options.name` from `-jnlpUrl` --- .../java/org/jvnet/hudson/test/InboundAgentRule.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jvnet/hudson/test/InboundAgentRule.java b/src/main/java/org/jvnet/hudson/test/InboundAgentRule.java index 2cbd5cf9d..cc680f39c 100644 --- a/src/main/java/org/jvnet/hudson/test/InboundAgentRule.java +++ b/src/main/java/org/jvnet/hudson/test/InboundAgentRule.java @@ -42,6 +42,7 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -53,6 +54,7 @@ import java.util.jar.JarFile; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Pattern; import org.apache.commons.io.FileUtils; import org.apache.tools.ant.util.JavaEnvUtils; import org.junit.rules.ExternalResource; @@ -331,10 +333,11 @@ public void start(AgentArguments agentArguments, Options options) throws Excepti cmd.add("Xrunjdwp:transport=dt_socket,server=y,address=" + (JenkinsRule.SLAVE_DEBUG_PORT + agentArguments.numberOfNodes - 1)); } cmd.addAll(List.of("-jar", agentArguments.agentJar.getAbsolutePath())); - if (agentArguments.agentJnlpUrl.endsWith("computer/" + options.getName() + "/slave-agent.jnlp") && remotingVersion(agentArguments.agentJar).isNewerThanOrEqualTo(new VersionNumber("3186.vc3b_7249b_87eb_"))) { - cmd.addAll(List.of("-url", agentArguments.agentJnlpUrl.replaceAll("computer/" + options.getName() + "/slave-agent.jnlp$", ""))); + var m = Pattern.compile("(.+)computer/([^/]+)/slave-agent[.]jnlp").matcher(agentArguments.agentJnlpUrl); + if (m.matches() && remotingVersion(agentArguments.agentJar).isNewerThanOrEqualTo(new VersionNumber("3186.vc3b_7249b_87eb_"))) { + cmd.addAll(List.of("-url", m.group(1))); cmd.addAll(List.of("-secret", agentArguments.secret)); - cmd.addAll(List.of("-name", options.getName())); + cmd.addAll(List.of("-name", URI.create(m.group(2)).getPath())); if (options.isWebSocket()) { cmd.add("-webSocket"); }