Skip to content

Commit

Permalink
Can revert to the standard Run.getEnvironment(TaskListener) now that …
Browse files Browse the repository at this point in the history
…Computer.currentComputer is saner (cf. JENKINS-2786).

Originally-Committed-As: 4d67cbd404488e810db2c3a5b05ed8fa8f9c692d
  • Loading branch information
jglick committed Mar 19, 2015
1 parent 284d595 commit b0afca7
Showing 1 changed file with 1 addition and 25 deletions.
Expand Up @@ -68,7 +68,7 @@ public abstract class DefaultStepContext extends StepContext {
if (key == EnvVars.class) {
Run<?,?> run = get(Run.class);
EnvironmentAction a = run.getAction(EnvironmentAction.class);
EnvVars env = a != null ? a.getEnvironment() : getEnvironment(run, get(TaskListener.class));
EnvVars env = a != null ? a.getEnvironment() : run.getEnvironment(get(TaskListener.class));
if (value != null) {
env = new EnvVars(env);
env.putAll((EnvVars) value); // context overrides take precedence over user settings
Expand Down Expand Up @@ -149,28 +149,4 @@ private <T> T castOrNull(Class<T> key, Object o) {
*/
protected abstract @Nonnull FlowNode getNode() throws IOException;

/**
* Temporary replacement for broken {@link Run#getEnvironment(TaskListener)}.
* TODO 1.591+ replace with standard version
*/
public static EnvVars getEnvironment(Run<?,?> run, TaskListener listener) throws IOException, InterruptedException {
EnvVars env = run.getParent().getEnvironment(null, listener);
env.putAll(run.getCharacteristicEnvVars());
for (EnvironmentContributor ec : EnvironmentContributor.all().reverseView()) {
if (ec instanceof CoreEnvironmentContributor) {
env.put("BUILD_DISPLAY_NAME", run.getDisplayName());
Jenkins j = Jenkins.getInstance();
if (j != null) {
String rootUrl = j.getRootUrl();
if (rootUrl != null) {
env.put("BUILD_URL", rootUrl + run.getUrl());
}
}
} else {
ec.buildEnvironmentFor(run, env, listener);
}
}
return env;
}

}

0 comments on commit b0afca7

Please sign in to comment.