Skip to content
Permalink
Browse files

Fix JENKINS-12963

  • Loading branch information...
gboissinot committed Mar 3, 2012
1 parent 1be2cee commit b4ea67db856dea01458351b9addc5a6c30bc3c7b
@@ -9,7 +9,6 @@
import hudson.slaves.NodeProperty; import hudson.slaves.NodeProperty;
import hudson.tasks.BuildWrapper; import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor; import hudson.tasks.BuildWrapperDescriptor;
import hudson.util.LogTaskListener;
import org.jenkinsci.lib.envinject.EnvInjectException; import org.jenkinsci.lib.envinject.EnvInjectException;
import org.jenkinsci.lib.envinject.EnvInjectLogger; import org.jenkinsci.lib.envinject.EnvInjectLogger;
import org.jenkinsci.plugins.envinject.model.EnvInjectJobPropertyContributor; import org.jenkinsci.plugins.envinject.model.EnvInjectJobPropertyContributor;
@@ -24,7 +23,6 @@
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;


/** /**
@@ -132,8 +130,8 @@ private Environment setUpEnvironmentNonMatrixRun(AbstractBuild build, Launcher l
//Add Jenkins System variables //Add Jenkins System variables
if (envInjectJobProperty.isKeepJenkinsSystemVariables()) { if (envInjectJobProperty.isKeepJenkinsSystemVariables()) {
logger.info("Jenkins system variables are kept."); logger.info("Jenkins system variables are kept.");
infraEnvVarsMaster.putAll(getJenkinsSystemVariables(build, true)); infraEnvVarsMaster.putAll(getJenkinsSystemVariables(true));
infraEnvVarsNode.putAll(getJenkinsSystemVariables(build, false)); infraEnvVarsNode.putAll(getJenkinsSystemVariables(false));
} }


//Add build variables //Add build variables
@@ -208,7 +206,7 @@ private boolean isMatrixRun(AbstractBuild build) {
return build instanceof MatrixRun; return build instanceof MatrixRun;
} }


private Map<String, String> getJenkinsSystemVariables(AbstractBuild build, boolean onMaster) throws IOException, InterruptedException { private Map<String, String> getJenkinsSystemVariables(boolean onMaster) throws IOException, InterruptedException {


Map<String, String> result = new TreeMap<String, String>(); Map<String, String> result = new TreeMap<String, String>();


@@ -226,29 +224,16 @@ private boolean isMatrixRun(AbstractBuild build) {
if (n != null) if (n != null)
result.put("NODE_NAME", computer.getName()); result.put("NODE_NAME", computer.getName());
result.put("NODE_LABELS", Util.join(n.getAssignedLabels(), " ")); result.put("NODE_LABELS", Util.join(n.getAssignedLabels(), " "));

Executor e = build.getExecutor();
if (e != null) {
result.put("EXECUTOR_NUMBER", String.valueOf(e.getNumber()));
}
} }


String rootUrl = Hudson.getInstance().getRootUrl(); String rootUrl = Hudson.getInstance().getRootUrl();
if (rootUrl != null) { if (rootUrl != null) {
result.put("JENKINS_URL", rootUrl); result.put("JENKINS_URL", rootUrl);
result.put("HUDSON_URL", rootUrl); // Legacy compatibility result.put("HUDSON_URL", rootUrl); // Legacy compatibility
result.put("BUILD_URL", rootUrl + build.getUrl());
result.put("JOB_URL", rootUrl + build.getParent().getUrl());
} }
result.put("JENKINS_HOME", Hudson.getInstance().getRootDir().getPath()); result.put("JENKINS_HOME", Hudson.getInstance().getRootDir().getPath());
result.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath()); // legacy compatibility result.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath()); // legacy compatibility


EnvVars envVars = new EnvVars();
for (EnvironmentContributor ec : EnvironmentContributor.all()) {
ec.buildEnvironmentFor(build, envVars, new LogTaskListener(LOG, Level.ALL));
result.putAll(envVars);
}

//Global properties //Global properties
for (NodeProperty<?> nodeProperty : Hudson.getInstance().getGlobalNodeProperties()) { for (NodeProperty<?> nodeProperty : Hudson.getInstance().getGlobalNodeProperties()) {
if (nodeProperty instanceof EnvironmentVariablesNodeProperty) { if (nodeProperty instanceof EnvironmentVariablesNodeProperty) {
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.envinject.service; package org.jenkinsci.plugins.envinject.service;


import hudson.EnvVars;
import hudson.FilePath; import hudson.FilePath;
import hudson.matrix.MatrixRun; import hudson.matrix.MatrixRun;
import hudson.model.*; import hudson.model.*;
@@ -70,6 +71,38 @@
//Add build process variables //Add build process variables
result.putAll(build.getCharacteristicEnvVars()); result.putAll(build.getCharacteristicEnvVars());


try {
EnvVars envVars = new EnvVars();
for (EnvironmentContributor ec : EnvironmentContributor.all()) {
ec.buildEnvironmentFor(build, envVars, new LogTaskListener(LOG, Level.ALL));
result.putAll(envVars);
}

JDK jdk = build.getProject().getJDK();
if (jdk != null) {
Node node = build.getBuiltOn();
if (node != null) {
jdk = jdk.forNode(node, logger.getListener());
}
jdk.buildEnvVars(result);
}
} catch (IOException ioe) {
throw new EnvInjectException(ioe);
} catch (InterruptedException ie) {
throw new EnvInjectException(ie);
}

Executor e = build.getExecutor();
if (e != null) {
result.put("EXECUTOR_NUMBER", String.valueOf(e.getNumber()));
}

String rootUrl = Hudson.getInstance().getRootUrl();
if (rootUrl != null) {
result.put("BUILD_URL", rootUrl + build.getUrl());
result.put("JOB_URL", rootUrl + build.getParent().getUrl());
}

//Add build variables such as parameters, plugins contributions, ... //Add build variables such as parameters, plugins contributions, ...
result.putAll(build.getBuildVariables()); result.putAll(build.getBuildVariables());


0 comments on commit b4ea67d

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