Skip to content
Browse files

Fix for JENKINS-14807

  • Loading branch information...
nfalco79 committed Jan 7, 2017
1 parent e452f3e commit dfefe0c16776c41a849894f8b738d52fcbb8a4ba
@@ -0,0 +1,38 @@

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;

@Extension(ordinal = -200)
public class FixEnvVarEnvironmentContributor extends EnvironmentContributor {

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);
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 dfefe0c

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