Skip to content
Permalink
Browse files

Fix JENKINS-16233

  • Loading branch information...
gboissinot committed Jan 19, 2013
1 parent 4cdc817 commit 23a7086f231e0647bfc24daceacaa1f078f5aa7f
@@ -59,7 +59,9 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, final Bui

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

//Add SCM variables if not set
@@ -58,7 +58,9 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

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

//Add SCM variables if not set
@@ -98,7 +100,9 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
result.putAll(build.getBuildVariables());
FilePath ws = build.getWorkspace();
if (ws != null) {
result.put("WORKSPACE", ws.getRemote());
if (result.get("WORKSPACE") == null) {
result.put("WORKSPACE", ws.getRemote());
}
}
return result;
}
@@ -182,7 +182,9 @@ public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener li

//Add workspace
FilePath ws = build.getWorkspace();
previousEnvVars.put("WORKSPACE", ws.getRemote());
if (previousEnvVars.get("WORKSPACE") == null) {
previousEnvVars.put("WORKSPACE", ws.getRemote());
}

//Resolve variables each other and with WORKSPACE
EnvInjectEnvVars envInjectEnvVars = new EnvInjectEnvVars(envInjectLogger);
@@ -57,4 +57,37 @@ public void testGlobalPropertiesWithWORKSPACE() throws Exception {

assertEquals(workspaceProcessed, testWorkspaceProcessed);
}

//Specific use case: We set a global workspace at job level
public void testGlobalPropertiesSetWORKSPACE() throws Exception {

final String testGlobalVariableName = "WORKSPACE";
final String testGlobalVariableValue = "WORKSPACE_VALUE";
final String testJobVariableName = "TEST_JOB_WORKSPACE";
final String testJobVariableExprValue = "${WORKSPACE}";

DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = Hudson.getInstance().getGlobalNodeProperties();
globalNodeProperties.add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry(testGlobalVariableName, testGlobalVariableValue)));

StringBuffer propertiesContent = new StringBuffer();
propertiesContent.append(testJobVariableName).append("=").append(testJobVariableExprValue);
EnvInjectJobPropertyInfo info = new EnvInjectJobPropertyInfo(
null, propertiesContent.toString(), null, null, null, true);
EnvInjectBuildWrapper envInjectBuildWrapper = new EnvInjectBuildWrapper();
envInjectBuildWrapper.setInfo(info);
project.getBuildWrappersList().add(envInjectBuildWrapper);

FreeStyleBuild build = project.scheduleBuild2(0).get();
Assert.assertEquals(Result.SUCCESS, build.getResult());

org.jenkinsci.lib.envinject.EnvInjectAction action = build.getAction(org.jenkinsci.lib.envinject.EnvInjectAction.class);
Map<String, String> envVars = action.getEnvMap();

String result_testGlobalVariableName = envVars.get(testGlobalVariableName);
assertNotNull(result_testGlobalVariableName);
String result_testJobVariableName = envVars.get(testJobVariableName);
assertNotNull(result_testJobVariableName);

assertEquals(result_testGlobalVariableName, result_testJobVariableName);
}
}

0 comments on commit 23a7086

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