提交 afcdb045 编写于 作者: P Pavel Janousek 提交者: Oleg Nenashev

[JENKINS-54772] Fix reported list of environment variables from agent (#3770)

* [JENKINS-54772] Fix reported list of environment variables from agent

* Feedback incorporated

* Code moved to SlaveComputer class
上级 374ce3a0
...@@ -26,6 +26,7 @@ package hudson.slaves; ...@@ -26,6 +26,7 @@ package hudson.slaves;
import hudson.AbortException; import hudson.AbortException;
import hudson.FilePath; import hudson.FilePath;
import hudson.Functions; import hudson.Functions;
import hudson.Main;
import hudson.RestrictedSince; import hudson.RestrictedSince;
import hudson.Util; import hudson.Util;
import hudson.console.ConsoleLogFilter; import hudson.console.ConsoleLogFilter;
...@@ -87,6 +88,8 @@ import java.security.Security; ...@@ -87,6 +88,8 @@ import java.security.Security;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -902,6 +905,32 @@ public class SlaveComputer extends Computer { ...@@ -902,6 +905,32 @@ public class SlaveComputer extends Computer {
return channel.call(new DetectOS()) ? "Unix" : "Windows"; return channel.call(new DetectOS()) ? "Unix" : "Windows";
} }
/**
* Expose real full env vars map from agent for UI presentation
*/
public Map<String,String> getEnvVarsFull() throws IOException, InterruptedException {
if(getChannel() == null) {
Map<String, String> env = new TreeMap<> ();
env.put("N/A","N/A");
return env;
} else {
return getChannel().call(new ListFullEnvironment());
}
}
private static class ListFullEnvironment extends MasterToSlaveCallable<Map<String,String>,IOException> {
public Map<String,String> call() throws IOException {
Map<String, String> env = new TreeMap<>(System.getenv());
if(Main.isUnitTest || Main.isDevelopmentMode) {
// if unit test is launched with maven debug switch,
// we need to prevent forked Maven processes from seeing it, or else
// they'll hang
env.remove("MAVEN_OPTS");
}
return env;
}
}
private static final Logger logger = Logger.getLogger(SlaveComputer.class.getName()); private static final Logger logger = Logger.getLogger(SlaveComputer.class.getName());
private static final class SlaveVersion extends MasterToSlaveCallable<String,IOException> { private static final class SlaveVersion extends MasterToSlaveCallable<String,IOException> {
......
...@@ -29,5 +29,5 @@ THE SOFTWARE. ...@@ -29,5 +29,5 @@ THE SOFTWARE.
--> -->
<?jelly escape-by-default='true'?> <?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<t:propertyTable items="${it.envVars}" /> <t:propertyTable items="${it.envVarsFull}" />
</j:jelly> </j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册