/** * Convenience message * @since 1.485 **/ public String get(String key, String defaultValue) { String v = get(key); if (v==null) v=defaultValue; return v; }
/** * 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); }
@Test @Issue("Issue #173") @ConfiguredWithCode("SetEnvironmentVariable.yml") public void shouldSetEnvironmentVariable() throws Exception { final DescribableList<NodeProperty<?>, NodePropertyDescriptor> properties = Jenkins.getInstance().getNodeProperties(); EnvVars env = new EnvVars(); for (NodeProperty<?> property : properties) { property.buildEnvVars(env, TaskListener.NULL); } assertEquals("BAR", env.get("FOO")); }
/** * Convenience message * @since 1.485 **/ public String get(String key, String defaultValue) { String v = get(key); if (v==null) v=defaultValue; return v; }
private void maybyPut(final String key, final EnvVars source, final EnvVars target) { String value = source.get(key); if (value != null) { target.put(key, value); } }
/** * Returns build details string in wiki format, with hyperlinks. * * @param vars * @return */ private String getBuildDetailsString(EnvVars vars) { final String buildURL = vars.get("BUILD_URL"); return String.format("[%s|%s] [console log|%s]", getBuildName(vars), buildURL, buildURL.concat("console")); }
private static AWSCredentialsProvider handleStaticCredentials(EnvVars vars) { String accessKey = vars.get(AWS_ACCESS_KEY_ID); String secretAccessKey = vars.get(AWS_SECRET_ACCESS_KEY); if (accessKey != null && secretAccessKey != null) { String sessionToken = vars.get(AWS_SESSION_TOKEN); if (sessionToken != null) { return new AWSStaticCredentialsProvider(new BasicSessionCredentials(accessKey, secretAccessKey, sessionToken)); } return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretAccessKey)); } return null; }
@Override public StepExecution start(StepContext context) throws Exception { String path = context.get(EnvVars.class).get("PATH"); if (path != null && path.contains("$PATH")) { context.get(TaskListener.class).getLogger().println("Warning: JENKINS-41339 probably bogus PATH=" + path + "; perhaps you meant to use ‘PATH+EXTRA=/something/bin’?"); } return super.start(context); }