Skip to content
Permalink
Browse files

Workaround for JENKINS-14807

  • Loading branch information...
nfalco79 committed Jan 7, 2017
1 parent e452f3e commit 89ec9ee9777b821a65e83f4220e0821b02606fd6
@@ -0,0 +1,38 @@
package jenkins.plugins.nodejs.tools.pathresolvers;

import java.io.IOException;
import java.lang.reflect.Field;

import javax.annotation.Nonnull;

import hudson.EnvVars;
import hudson.Extension;
import hudson.Platform;
import hudson.model.Computer;
import hudson.model.EnvironmentContributor;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.util.ReflectionUtils;

//@Issue("JENKINS-14807")
@Extension(ordinal = -200)
public class FixEnvVarEnvironmentContributor extends EnvironmentContributor {

@Override
public void buildEnvironmentFor(@SuppressWarnings("rawtypes") @Nonnull Run run, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException {
Computer c = Computer.currentComputer();
if (c != null) {
Field platformField = ReflectionUtils.findField(EnvVars.class, "platform", Platform.class);
ReflectionUtils.makeAccessible(platformField);
Platform currentPlatform = (Platform) ReflectionUtils.getField(platformField, envs);
if (currentPlatform == null) {
// try to fix value with than one that comes from current computer
EnvVars remoteEnv = c.getEnvironment();
Platform computerPlatform = (Platform) ReflectionUtils.getField(platformField, remoteEnv);
if (computerPlatform != null) {
ReflectionUtils.setField(platformField, envs, computerPlatform);
}
}
}
}
}

0 comments on commit 89ec9ee

Please sign in to comment.
You can’t perform that action at this time.