/** * @deprecated as of 1.292 * Use {@link #getEnvironment()} instead. */ @Deprecated public Map<String,String> getEnvVars() throws IOException, InterruptedException { return getEnvironment(); }
if (computer != null) { env = computer.getEnvironment(); env.putAll(computer.buildEnvironment(listener));
@Override public void buildEnvironmentFor(Run r, EnvVars env, TaskListener listener) throws IOException, InterruptedException { Computer c = Computer.currentComputer(); if (c!=null){ EnvVars compEnv = c.getEnvironment().overrideAll(env); env.putAll(compEnv); } env.put("BUILD_DISPLAY_NAME",r.getDisplayName()); Jenkins j = Jenkins.getInstance(); String rootUrl = j.getRootUrl(); if(rootUrl!=null) { env.put("BUILD_URL", rootUrl+r.getUrl()); } }
/** * @deprecated as of 1.292 * Use {@link #getEnvironment()} instead. */ public Map<String,String> getEnvVars() throws IOException, InterruptedException { return getEnvironment(); }
/** * @deprecated as of 1.292 Use {@link #getEnvironment()} instead. */ public Map<String, String> getEnvVars() throws IOException, InterruptedException { return getEnvironment(); }
/** * @deprecated as of 1.292 * Use {@link #getEnvironment()} instead. */ public Map<String,String> getEnvVars() throws IOException, InterruptedException { return getEnvironment(); }
/** * @deprecated as of 1.292 * Use {@link #getEnvironment()} instead. */ public Map<String,String> getEnvVars() throws IOException, InterruptedException { return getEnvironment(); }
/** * @deprecated as of 1.292 * Use {@link #getEnvironment()} instead. */ @Deprecated public Map<String,String> getEnvVars() throws IOException, InterruptedException { return getEnvironment(); }
private List<EnvVar> createPodEnv(Map<String,String> explicit) throws IOException, InterruptedException { List<EnvVar> podEnv = new ArrayList<EnvVar>(); EnvVars envReduced = new EnvVars(env); EnvVars envHost = computer.getEnvironment(); envReduced.entrySet().removeAll(envHost.entrySet()); for (Map.Entry<String, String> entry : envReduced.entrySet()) { podEnv.add(new EnvVar(entry.getKey(), entry.getValue(), null)); } for (Map.Entry<String, String> entry : explicit.entrySet()) { podEnv.add(new EnvVar(entry.getKey(), entry.getValue(), null)); } return podEnv; }
/** * @return resolved variable or null if the lookup failed */ public String resolve(final String variable) { try { if (lazyResolvers.containsKey(variable)) { return lazyResolvers.get(variable).getValue(); } else { if (computer != null) { otherResolvers.add(new VariableResolver.ByMap<String>(computer.getEnvironment())); } return new VariableResolver.Union<String>(otherResolvers).resolve(variable); } } catch (Exception e) { LOGGER.warning("Variable name '" + variable + "' look up failed because of " + e); } return null; }
public String getMavenOpts() { String mavenOpts = mms.getMavenOpts(); if ((mavenOpts==null) || (mavenOpts.trim().length()==0)) { Node n = getCurrentNode(); if (n!=null) { try { String localMavenOpts = n.toComputer().getEnvironment().get("MAVEN_OPTS"); if ((localMavenOpts!=null) && (localMavenOpts.trim().length()>0)) { mavenOpts = localMavenOpts; } } catch (IOException e) { } catch (InterruptedException e) { // Don't do anything - this just means the slave isn't running, so we // don't want to use its MAVEN_OPTS anyway. } } } return envVars.expand(mavenOpts); }
/** * 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; }
public String getMavenOpts() { if( this.mavenOpts != null ) return addRunHeadLessOption(this.mavenOpts); String mavenOpts = mms.getMavenOpts(); if ((mavenOpts==null) || (mavenOpts.trim().length()==0)) { Node n = getCurrentNode(); if (n!=null) { try { String localMavenOpts = n.toComputer().getEnvironment().get("MAVEN_OPTS"); if ((localMavenOpts!=null) && (localMavenOpts.trim().length()>0)) { mavenOpts = localMavenOpts; } } catch (IOException e) { } catch (InterruptedException e) { // Don't do anything - this just means the slave isn't running, so we // don't want to use its MAVEN_OPTS anyway. } } } mavenOpts = addRunHeadLessOption(mavenOpts); return envVars.expand(mavenOpts); }
@Override public Proc launch(ProcStarter starter) throws IOException { LOGGER.log(Level.FINEST, "Launch proc with environment: {0}", Arrays.toString(starter.envs())); String[] envVars = starter.envs(); if (node != null) { // It seems this is possible despite the method javadoc saying it is non-null final Computer computer = node.toComputer(); if (computer != null) { List<String> resultEnvVar = new ArrayList<>(); try { EnvVars environment = computer.getEnvironment(); String[] envs = starter.envs(); for (String keyValue : envs) { String[] split = keyValue.split("=", 2); if (!split[1].equals(environment.get(split[0]))) { // Only keep environment variables that differ from Computer's environment resultEnvVar.add(keyValue); } } envVars = resultEnvVar.toArray(new String[resultEnvVar.size()]); } catch (InterruptedException e) { throw new IOException("Unable to retrieve environment variables", e); } } } return doLaunch(starter.quiet(), envVars, starter.stdout(), starter.pwd(), starter.masks(), getCommands(starter)); }
/** * Gets a combined set of environment variables for the current computer and build. * * @param build The build for which we should retrieve environment variables. * @param listener The listener used to get the environment variables. * @return Environment variables for the current computer, with the build variables taking precedence. */ public static EnvVars getEnvironment(AbstractBuild<?, ?> build, BuildListener listener) { final EnvVars envVars = new EnvVars(); try { // Get environment of the local computer EnvVars localVars = Computer.currentComputer().getEnvironment(); envVars.putAll(localVars); // Add variables specific to this build envVars.putAll(build.getEnvironment(listener)); } catch (InterruptedException e) { // Ignore } catch (IOException e) { // Ignore } return envVars; }
if (computer != null) { env = computer.getEnvironment(); env.putAll(computer.buildEnvironment(listener));
/** * Expands the variable in the given string to its value in the environment variables available * to this build. The Jenkins-specific build variables for this build are then substituted. * * @param build The build from which to get the build-specific and environment variables. * @param listener The listener used to get the environment variables. * @param token The token which may or may not contain variables in the format <tt>${foo}</tt>. * @return The given token, with applicable variable expansions done. */ public static String expandVariables(AbstractBuild<?,?> build, BuildListener listener, String token) { EnvVars envVars; Map<String, String> buildVars; try { EnvVars localVars = Computer.currentComputer().getEnvironment(); envVars = new EnvVars(localVars); envVars.putAll(build.getEnvironment(listener)); buildVars = build.getBuildVariables(); } catch (IOException e) { return null; } catch (InterruptedException e) { return null; } return expandVariables(envVars, buildVars, token); }
@Override public void buildEnvironmentFor(Run r, EnvVars env, TaskListener listener) throws IOException, InterruptedException { Computer c = Computer.currentComputer(); if (c!=null){ EnvVars compEnv = c.getEnvironment().overrideAll(env); env.putAll(compEnv); } env.put("BUILD_DISPLAY_NAME",r.getDisplayName()); Jenkins j = Jenkins.getInstance(); String rootUrl = j.getRootUrl(); if(rootUrl!=null) { env.put("BUILD_URL", rootUrl+r.getUrl()); } }
/** * Replace macro with environment variable if it exists. * * @param build * @param listener * @param macro * @return * @throws InterruptedException */ public static String applyMacro(AbstractBuild<?, ?> build, BuildListener listener, String macro) throws InterruptedException { try { EnvVars envVars = new EnvVars(Computer.currentComputer().getEnvironment()); envVars.putAll(build.getEnvironment(listener)); envVars.putAll(build.getBuildVariables()); return Util.replaceMacro(macro, envVars); } catch (IOException e) { Utils.loggerMessage(listener, 0, "[{0}] ERROR, FAILED TO APPLY MACRO: {1}", Utils.ZAP, macro); listener.error(ExceptionUtils.getStackTrace(e)); } return macro; }
private void invokeBody(DockerTransientNode node, TaskListener listener) { this.nodeName = node.getNodeName(); FilePath ws = null; Computer computer = null; EnvVars env = null; try { // TODO workspace should be a volume ws = node.createPath(node.getRemoteFS() + "/workspace"); FlowNode flowNode = getContext().get(FlowNode.class); flowNode.addAction(new WorkspaceActionImpl(ws, flowNode)); computer = node.toComputer(); if (computer == null) throw new IllegalStateException("Agent not started"); env = computer.getEnvironment(); env.overrideExpandingAll(computer.buildEnvironment(listener)); env.put("NODE_NAME", computer.getName()); env.put("EXECUTOR_NUMBER", "0"); env.put("NODE_LABELS", Util.join(node.getAssignedLabels(), " ")); env.put("WORKSPACE", ws.getRemote()); } catch (IOException | InterruptedException e) { getContext().onFailure(e); } getContext().newBodyInvoker().withCallback(new Callback(node)).withContexts(computer, env, ws).start(); }