Skip to content
Permalink
Browse files

Fix JENKINS-13022

  • Loading branch information
gboissinot committed Mar 9, 2012
1 parent 29ecfaf commit bf15513e57f910d0376bca9f4f9c22cf1966d637
@@ -49,10 +49,15 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, final Bui
EnvInjectEnvVars envInjectEnvVarsService = new EnvInjectEnvVars(logger);

try {
Map<String, String> previousEnvVars = variableGetter.getEnvVarsPreviousSteps(build, logger);

Map<String, String> previousEnvVars = variableGetter.getEnvVarsPreviousSteps(build, logger);
Map<String, String> injectedEnvVars = new HashMap<String, String>(previousEnvVars);

//Add workspace if not set
if (ws != null) {
injectedEnvVars.put("WORKSPACE", ws.getRemote());
}

//Get result variables
Map<String, String> propertiesEnvVars = envInjectEnvVarsService.getEnvVarsPropertiesProperty(ws, logger, info.getPropertiesFilePath(), info.getPropertiesContentMap(), injectedEnvVars);

@@ -55,6 +55,11 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
//Get current envVars
Map<String, String> variables = new HashMap<String, String>(previousEnvVars);

//Add workspace if not set
if (ws != null) {
variables.put("WORKSPACE", ws.getRemote());
}

//Always keep build variables (such as parameter variables).
variables.putAll(getAndAddBuildVariables(build));

@@ -37,6 +37,7 @@ public Environment setUpEnvironment(AbstractBuild build, Launcher launcher, Buil
if (isEnvInjectJobPropertyActive(build)) {
if (!isMatrixRun(build)) {
addBuildWrapper(build, new JobSetupEnvironmentWrapper());
return setUpEnvironmentNonMatrixRun(build, launcher, listener);
} else {
return setUpEnvironmentMatrixRun(build, listener);
}
@@ -73,23 +74,6 @@ private void addBuildWrapper(AbstractBuild build, BuildWrapper buildWrapper) thr
}
}

private void removeBuildWrapper(AbstractBuild build, BuildWrapper buildWrapper) throws EnvInjectException {
try {
if (buildWrapper != null) {
AbstractProject abstractProject = build.getProject();
if (abstractProject instanceof MatrixProject) {
MatrixProject project = (MatrixProject) abstractProject;
project.getBuildWrappersList().remove(buildWrapper);
} else {
Project project = (Project) abstractProject;
project.getBuildWrappersList().remove(buildWrapper);
}
}
} catch (IOException ioe) {
throw new EnvInjectException(ioe);
}
}

private boolean isEnvInjectJobPropertyActive(AbstractBuild build) {
EnvInjectVariableGetter variableGetter = new EnvInjectVariableGetter();
EnvInjectJobProperty envInjectJobProperty = variableGetter.getEnvInjectJobProperty(build);
@@ -98,21 +82,8 @@ private boolean isEnvInjectJobPropertyActive(AbstractBuild build) {


public static class JobSetupEnvironmentWrapper extends BuildWrapper {
@Override
public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
try {
new EnvInjectListener().setUpEnvironmentNonMatrixRun(build, launcher, listener);
} catch (EnvInjectException e) {
throw new IOException(e);
}
}

@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
return new Environment() {
};
}

@SuppressWarnings("unused")
@Extension
public static class JobSetupEnvironmentWrapperDescriptor extends BuildWrapperDescriptor {

@@ -133,6 +104,36 @@ public String getDisplayName() {
return null;
}
}

@Override
public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {

EnvInjectLogger envInjectLogger = new EnvInjectLogger(listener);
EnvInjectVariableGetter variableGetter = new EnvInjectVariableGetter();
EnvInjectJobProperty envInjectJobProperty = variableGetter.getEnvInjectJobProperty(build);

assert envInjectJobProperty != null;

if (envInjectJobProperty.isKeepBuildVariables()) {
try {
//Get previous
Map<String, String> previousEnvVars = variableGetter.getEnvVarsPreviousSteps(build, envInjectLogger);
//Add workspace
FilePath ws = build.getWorkspace();
previousEnvVars.put("WORKSPACE", ws.getRemote());
//Set new env vars
new EnvInjectActionSetter(build.getBuiltOn().getRootPath()).addEnvVarsToEnvInjectBuildAction(build, previousEnvVars);
} catch (EnvInjectException e) {
throw new IOException(e);
}
}
}

@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
return new Environment() {
};
}
}

private Environment setUpEnvironmentNonMatrixRun(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, EnvInjectException {
@@ -464,5 +465,4 @@ private void maskPasswordsIfAny(AbstractBuild build, EnvInjectLogger logger, Map
}
}


}
@@ -1,7 +1,6 @@
package org.jenkinsci.plugins.envinject.service;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.matrix.MatrixRun;
import hudson.model.*;
import hudson.slaves.EnvironmentVariablesNodeProperty;
@@ -110,10 +109,6 @@
Map<String, String> triggerVariable = new BuildCauseRetriever().getTriggeredCause(build);
result.putAll(triggerVariable);

//Add workspace
FilePath ws = build.getWorkspace();
result.put("WORKSPACE", ws.getRemote());

return result;
}

@@ -171,12 +166,6 @@ public EnvInjectJobProperty getEnvInjectJobProperty(AbstractBuild build) {
if (envInjectDetector.isEnvInjectActivated(build)) {
result.putAll(getCurrentInjectedEnvVars(build));

//Add workspace if not set
FilePath ws = build.getWorkspace();
if (ws != null) {
result.put("WORKSPACE", ws.getRemote());
}

//Add build variables with axis for a MatrixRun
if (build instanceof MatrixRun) {
result.putAll(build.getBuildVariables());

0 comments on commit bf15513

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