private static EnvVars initMaster() { EnvVars vars = new EnvVars(System.getenv()); vars.platform = Platform.current(); 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 vars.remove("MAVEN_OPTS"); return vars; } }
/** * Overrides the current entry by the given entry. * * <p> * Handles {@code PATH+XYZ} notation. */ public void override(String key, String value) { if(value==null || value.length()==0) { remove(key); return; } int idx = key.indexOf('+'); if(idx>0) { String realKey = key.substring(0,idx); String v = get(realKey); if(v==null) v=value; else { // we might be handling environment variables for a agent that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform==null ? File.pathSeparatorChar : platform.pathSeparator; v=value+ch+v; } put(realKey,v); return; } put(key,value); }
private void env(String name, String value) { if (value==null) environment.remove(name); else environment.put(name,value); }
private static EnvVars initMaster() { EnvVars vars = new EnvVars(System.getenv()); vars.platform = Platform.current(); 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 vars.remove("MAVEN_OPTS"); return vars; } }
private static EnvVars initMaster() { EnvVars vars = new EnvVars(System.getenv()); vars.platform = Platform.current(); 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 vars.remove("MAVEN_OPTS"); return vars; } }
private static EnvVars initMaster() { EnvVars vars = new EnvVars(System.getenv()); vars.platform = Platform.current(); 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 vars.remove("MAVEN_OPTS"); return vars; } }
private static EnvVars initMaster() { EnvVars vars = new EnvVars(System.getenv()); vars.platform = Platform.current(); 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 vars.remove("MAVEN_OPTS"); return vars; } }
private static EnvVars initMaster() { EnvVars vars = new EnvVars(System.getenv()); vars.platform = Platform.current(); 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 { vars.remove("MAVEN_OPTS"); } return vars; } }
@Override public Void call() throws EnvInjectException { try { Field platformField = EnvVars.class.getDeclaredField("platform"); platformField.setAccessible(true); platformField.set(enVars, Platform.current()); if (Main.isUnitTest || Main.isDevelopmentMode) { enVars.remove("MAVEN_OPTS"); } Field masterEnvVarsFiled = EnvVars.class.getDeclaredField("masterEnvVars"); masterEnvVarsFiled.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(masterEnvVarsFiled, masterEnvVarsFiled.getModifiers() & ~Modifier.FINAL); masterEnvVarsFiled.set(null, enVars); } catch (IllegalAccessException iae) { throw new EnvInjectException(iae); } catch (NoSuchFieldException nsfe) { throw new EnvInjectException(nsfe); } return null; }
/** * Overrides the current entry by the given entry. * * <p> Handles <tt>PATH+XYZ</tt> notation. */ public void override(String key, String value) { if (value == null || value.length() == 0) { remove(key); return; } int idx = key.indexOf('+'); if (idx > 0) { String realKey = key.substring(0, idx); String v = get(realKey); if (v == null) { v = value; } else { // we might be handling environment variables for a slave that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform == null ? File.pathSeparatorChar : platform.pathSeparator; v = value + ch + v; } put(realKey, v); return; } put(key, value); }
/** * Overrides the current entry by the given entry. * * <p> * Handles <tt>PATH+XYZ</tt> notation. */ public void override(String key, String value) { if(value==null || value.length()==0) { remove(key); return; } int idx = key.indexOf('+'); if(idx>0) { String realKey = key.substring(0,idx); String v = get(realKey); if(v==null) v=value; else { // we might be handling environment variables for a agent that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform==null ? File.pathSeparatorChar : platform.pathSeparator; v=value+ch+v; } put(realKey,v); return; } put(key,value); }
/** * Overrides the current entry by the given entry. * * <p> * Handles <tt>PATH+XYZ</tt> notation. */ public void override(String key, String value) { if(value==null || value.length()==0) { remove(key); return; } int idx = key.indexOf('+'); if(idx>0) { String realKey = key.substring(0,idx); String v = get(realKey); if(v==null) v=value; else { // we might be handling environment variables for a slave that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform==null ? File.pathSeparatorChar : platform.pathSeparator; v=value+ch+v; } put(realKey,v); return; } put(key,value); }
/** * Overrides the current entry by the given entry. * * <p> * Handles <tt>PATH+XYZ</tt> notation. */ public void override(String key, String value) { if(value==null || value.length()==0) { remove(key); return; } int idx = key.indexOf('+'); if(idx>0) { String realKey = key.substring(0,idx); String v = get(realKey); if(v==null) v=value; else { // we might be handling environment variables for a slave that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform==null ? File.pathSeparatorChar : platform.pathSeparator; v=value+ch+v; } put(realKey,v); return; } put(key,value); }
/** * Overrides the current entry by the given entry. * * <p> * Handles <tt>PATH+XYZ</tt> notation. */ public void override(String key, String value) { if(value==null || value.length()==0) { remove(key); return; } int idx = key.indexOf('+'); if(idx>0) { String realKey = key.substring(0,idx); String v = get(realKey); if(v==null) v=value; else { // we might be handling environment variables for a slave that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform==null ? File.pathSeparatorChar : platform.pathSeparator; v=value+ch+v; } put(realKey,v); return; } put(key,value); }
/** * Create the container environment. * We can't just pass result of {@link AbstractBuild#getEnvironment(TaskListener)}, as this one do include slave host * environment, that may not make any sense inside container (consider <code>PATH</code> for sample). */ private EnvVars buildContainerEnvironment(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException { EnvVars env = build.getEnvironment(listener); for (String key : Computer.currentComputer().getEnvironment().keySet()) { env.remove(key); } LOGGER.log(Level.FINE, "reduced environment: {0}", env); EnvVars.resolve(env); return env; }
environment.remove(key);
environment.remove(key);
/** * Return all job related vars without executor vars. * I.e. slave is running in osx, but docker image for shell is linux. */ protected static EnvVars getEnvVars(Run run, TaskListener listener) throws IOException, InterruptedException { final EnvVars envVars = run.getCharacteristicEnvVars(); // from run.getEnvironment(listener) but without computer vars for (EnvironmentContributor ec : EnvironmentContributor.all().reverseView()) { // job vars ec.buildEnvironmentFor(run.getParent(), envVars, listener); // build vars if (ec instanceof CoreEnvironmentContributor) { // exclude executor computer related vars envVars.put("BUILD_DISPLAY_NAME", run.getDisplayName()); String rootUrl = Jenkins.getInstance().getRootUrl(); if (rootUrl != null) { envVars.put("BUILD_URL", rootUrl + run.getUrl()); } // and remove useless job var from CoreEnvironmentContributor envVars.remove("JENKINS_HOME"); envVars.remove("HUDSON_HOME"); } else { ec.buildEnvironmentFor(run, envVars, listener); // build vars } } return envVars; }
env.remove(JAVA_OPTS_KEY);