Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

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).
  • Loading branch information
jglick committed Mar 19, 2015
1 parent 0e6b10e commit 4d67cbd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
Expand Up @@ -37,7 +37,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.RunAction2;
import org.jenkinsci.plugins.workflow.support.DefaultStepContext;
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
Expand All @@ -58,7 +57,7 @@ public class EnvActionImpl extends GroovyObjectSupport implements EnvironmentAct

@Override public EnvVars getEnvironment() throws IOException, InterruptedException {
if (ownerEnvironment == null) {
ownerEnvironment = DefaultStepContext.getEnvironment(owner, new LogTaskListener(LOGGER, Level.INFO));
ownerEnvironment = owner.getEnvironment(new LogTaskListener(LOGGER, Level.INFO));
}
EnvVars e = new EnvVars(ownerEnvironment);
e.putAll(env);
Expand Down
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 4d67cbd

Please sign in to comment.