/** * @return environment variables using same data type as constructor parameter. * @since 2.136 */ public List<Entry> getEnv() { return envVars.entrySet().stream().map(Entry::new).collect(Collectors.toList()); }
private ExpanderImpl(EnvVars overrides) { LOGGER.log(Level.FINEST, "ExpanderImpl(overrides: {0})", new Object[]{overrides}); this.overrides = new HashMap<>(); for (Entry<String, String> entry : overrides.entrySet()) { this.overrides.put(entry.getKey(), entry.getValue()); } }
public GitAPI(String gitExe, FilePath workspace, TaskListener listener, EnvVars environment) { //listener.getLogger().println("Git API @ " + workspace.getName() + " / " + workspace.getRemote() + " - " + workspace.getChannel()); this.workspace = workspace; this.listener = listener; this.gitExe = gitExe; this.environment = environment; // PrintStream log = listener.getLogger(); for (Map.Entry<String, String> ent : environment.entrySet()) { //log.println("Env: " + ent.getKey() + "=" + ent.getValue()); } launcher = new LocalLauncher(GitSCM.VERBOSE ? listener : TaskListener.NULL); }
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; }
private void setupEnvironmentVariable(EnvVars vars, ExecWatch watch) throws IOException { for (Map.Entry<String, String> entry : vars.entrySet()) { //Check that key is bash compliant. if (entry.getKey().matches("[a-zA-Z_][a-zA-Z0-9_]*")) { watch.getInput().write( String.format( "export %s='%s'%s", entry.getKey(), entry.getValue().replace("'", "'\\''"), NEWLINE ).getBytes(StandardCharsets.UTF_8) ); } } }
private void addEnvVariables(BuildInfoBuilder builder, IncludeExcludePatterns patterns) { for (Map.Entry<String, String> entry : env.entrySet()) { String varKey = entry.getKey(); if (PatternMatcher.pathConflicts(varKey, patterns)) { continue; } builder.addProperty(BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX + varKey, entry.getValue()); } }
/** See if sensitive environment variable content is in a string */ public static boolean isStringSafe(@CheckForNull String input, @CheckForNull EnvVars variables, @Nonnull Set<String> safeEnvVariables) { if (input == null || variables == null || variables.size() == 0) { return true; } StringBuilder pattern = new StringBuilder(); int count = 0; for (Map.Entry<String,String> ent : variables.entrySet()) { String val = ent.getValue(); if (val == null || val.isEmpty() || safeEnvVariables.contains(ent.getKey())) { // Skip values that are safe continue; } if (count > 0) { pattern.append('|'); } pattern.append(Pattern.quote(val)); count++; } return (count > 0) ? !Pattern.compile(pattern.toString()).matcher(input).find() : true; }
@Override public void buildEnvVars(AbstractBuild<?,?> build, Map<String, String> env) { // Add each SCM's env vars, appending indices where needed to avoid collisions for (int i = 0; i < scms.size(); i++) { try { EnvVars currScmVars = new EnvVars(); scms.get(i).buildEnvVars(build, currScmVars); for (Entry<String, String> entry : currScmVars.entrySet()) { if (env.containsKey(entry.getKey())) { // We have a collision; append the index of this SCM to the env var name env.put(entry.getKey() + "_" + i, entry.getValue()); } else { // No collision; just put the var as usual env.put(entry.getKey(), entry.getValue()); } } } catch(NullPointerException npe) {} } }
static String getUrlWithoutRevision( String remoteUrlPossiblyWithRevision) { String remoteUrlWithoutRevision = remoteUrlPossiblyWithRevision; if (Hudson.getInstance() != null) { for (NodeProperty n: Hudson.getInstance().getGlobalNodeProperties()) { EnvironmentVariablesNodeProperty gnp = (EnvironmentVariablesNodeProperty)n; for (Entry e : gnp.getEnvVars().entrySet()) { if (remoteUrlWithoutRevision.contains("${" + e.getKey().toString() + "}")) { remoteUrlWithoutRevision = remoteUrlWithoutRevision.replace("${" + e.getKey().toString() + "}", e.getValue().toString()); } } } } int idx = remoteUrlWithoutRevision.lastIndexOf('@'); if (idx > 0) { String n = remoteUrlWithoutRevision.substring(idx + 1); SVNRevision r = SVNRevision.parse(n); if ((r != null) && (r.isValid())) { return remoteUrlWithoutRevision.substring(0, idx); } } return remoteUrlWithoutRevision; }
public void executeIn(String container, String userId, Launcher.ProcStarter starter, EnvVars environment) throws IOException, InterruptedException { List<String> prefix = dockerCommandArgs(); prefix.add("exec"); prefix.add("--tty"); prefix.add("--user"); prefix.add(userId); prefix.add(container); prefix.add("env"); // Build a list of environment, hidding node's one for (Map.Entry<String, String> e : environment.entrySet()) { prefix.add(e.getKey()+"="+e.getValue()); } starter.cmds().addAll(0, prefix); if (starter.masks() != null) { boolean[] masks = new boolean[starter.masks().length + prefix.size()]; System.arraycopy(starter.masks(), 0, masks, prefix.size(), starter.masks().length); starter.masks(masks); } starter.envs(getEnvVars()); }
/** * Collects environment variables from an array and an EnvVars object and returns an updated EnvVars object. * This is useful for updating the environment variables on a ProcStarter with the variables from the listener. */ public static String[] addEnvVars(String[] envVarsArray, EnvVars envVars){ // All variables are stored on a map, the ones from ProcStarter will take precedence. EnvVars resultMap = new EnvVars(envVars); resultMap.putAll(arrayToMap(envVarsArray)); String[] r = new String[resultMap.size()]; int idx=0; for (Map.Entry<String,String> e : resultMap.entrySet()) { r[idx++] = e.getKey() + '=' + e.getValue(); } return r; }
argb.add("--volumes-from", containerId); for (Map.Entry<String, String> variable : containerEnv.entrySet()) { argb.add("-e"); argb.addMasked(variable.getKey()+"="+variable.getValue());
@Override protected List<String> run() throws Exception { String toolVersion = step.getToolVersion(); String toolId = step.getToolId(); for (ToolDescriptor<?> desc : ToolInstallation.all()) { if (toolId != null && !desc.getId().equals(toolId)) { continue; } for (ToolInstallation tool : desc.getInstallations()) { if (tool.getName().equals(toolVersion)) { if (tool instanceof NodeSpecific) { tool = (ToolInstallation) ((NodeSpecific<?>) tool).forNode(node, listener); } if (tool instanceof EnvironmentSpecific) { tool = (ToolInstallation) ((EnvironmentSpecific<?>) tool).forEnvironment(env); } List<String> toolEnvList = new ArrayList<>(); EnvVars toolEnv = new EnvVars(); tool.buildEnvVars(toolEnv); for (Map.Entry<String,String> entry: toolEnv.entrySet()) { toolEnvList.add(entry.getKey() + "=" + entry.getValue()); } return toolEnvList; } } } throw new AbortException("No tool of type " + toolId + " named " + toolVersion + " found"); }
/** * Build the environment. */ public EnvVars buildEnv() throws Exception { ensureNotNull(env); // These are for windows only if (windows) { env.put(MAVEN_TERMINATE_CMD, ON); env.put(MAVEN_BATCH_ECHO, OFF); env.put(MAVEN_BATCH_PAUSE, OFF); } env.put(M2_HOME, normalize(ensureNotNull(mavenHome)).getRemote()); env.put(MAVEN_OPTS, buildOpts().toStringWithQuote()); env.put(MAVEN_SKIP_RC, TRUE); if (log.isDebugEnabled()) { log.debug("Environment:"); for (Map.Entry<String, String> entry : env.entrySet()) { log.debug(" {}='{}'", entry.getKey(), entry.getValue()); } } return env; }
for (Map.Entry<String, String> e : environment.entrySet()) { if ("HOSTNAME".equals(e.getKey())) { continue;
private static void addEnvVars(Map<String, String> env, Run<?, ?> build, ArtifactoryClientConfiguration configuration, IncludesExcludes envVarsPatterns, TaskListener listener) { IncludeExcludePatterns patterns = new IncludeExcludePatterns( Util.replaceMacro(envVarsPatterns.getIncludePatterns(), env), Util.replaceMacro(envVarsPatterns.getExcludePatterns(), env) ); // Add only the jenkins specific environment variables MapDifference<String, String> envDifference = Maps.difference(env, System.getenv()); Map<String, String> filteredEnvDifference = envDifference.entriesOnlyOnLeft(); configuration.info.addBuildVariables(filteredEnvDifference, patterns); // Add Jenkins build variables EnvVars buildVariables = getEnvVars(build, listener); MapDifference<String, String> buildVarDifference = Maps.difference(buildVariables, System.getenv()); Map<String, String> filteredBuildVarDifferences = buildVarDifference.entriesOnlyOnLeft(); configuration.info.addBuildVariables(filteredBuildVarDifferences, patterns); // Write all the deploy (matrix params) properties. configuration.fillFromProperties(buildVariables, patterns); for (Map.Entry<String, String> entry : buildVariables.entrySet()) { if (entry.getKey().startsWith(ClientProperties.PROP_DEPLOY_PARAM_PROP_PREFIX)) { configuration.publisher.addMatrixParam(entry.getKey(), entry.getValue()); } } MultiConfigurationUtils.addMatrixCombination(build, configuration); }
for (Entry<String,String> entry : covEnvVars.entrySet()) { context.env(entry.getKey(), entry.getValue());
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { EnvVars vars = new EnvVars(); ParametersAction parametersAction = build.getAction(ParametersAction.class); if (parametersAction != null) { parametersAction.buildEnvVars(build, vars); } else { listener.error("Build was scheduled without parameters!"); return false; } for (Map.Entry<String, String> entry : vars.entrySet()) { listener.getLogger().println(entry.getKey() + "=" + entry.getValue()); } return true; }
EnvVars envScm = new EnvVars(); target.getProject().getScm().buildEnvVars( target, envScm ); for ( Entry<String, String> entry : envScm.entrySet() )
for (Entry<String,String> entry : envVars.entrySet()) { if (entry.getKey() != null && entry.getValue() != null) { this.properties.put( "env." + entry.getKey(), entry.getValue() );