Skip to content

Commit

Permalink
Workaround for JENKINS-14807
Browse files Browse the repository at this point in the history
  • Loading branch information
nfalco79 committed Jan 8, 2017
1 parent e452f3e commit 89ec9ee
Showing 1 changed file with 38 additions and 0 deletions.
@@ -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.