Skip to content

Commit

Permalink
Add a regression test to fix JENKINS-15658
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Nov 2, 2012
1 parent b1d9dbe commit be86097
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
Expand Up @@ -21,7 +21,7 @@
*/
public class EnvInjectJobProperty<T extends Job<?, ?>> extends JobProperty<T> {

private EnvInjectJobPropertyInfo info;
private EnvInjectJobPropertyInfo info = new EnvInjectJobPropertyInfo();
private boolean on;
private boolean keepJenkinsSystemVariables;
private boolean keepBuildVariables;
Expand Down
Expand Up @@ -13,6 +13,10 @@ public class EnvInjectJobPropertyInfo extends EnvInjectInfo {
private String groovyScriptContent;
private boolean loadFilesFromMaster;

public EnvInjectJobPropertyInfo() {
super(null, null);
}

@DataBoundConstructor
public EnvInjectJobPropertyInfo(String propertiesFilePath, String propertiesContent, String scriptFilePath, String scriptContent, String groovyScriptContent, boolean loadFilesFromMaster) {
super(propertiesFilePath, propertiesContent);
Expand Down
@@ -0,0 +1,60 @@
package org.jenkinsci.plugins.envinject;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Hudson;
import hudson.model.Result;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.util.DescribableList;
import junit.framework.Assert;
import org.jvnet.hudson.test.HudsonTestCase;

import java.util.Map;

/**
* @author Gregory Boissinot
*/
public class GlobalPropertiesTest extends HudsonTestCase {


private FreeStyleProject project;

@Override
public void setUp() throws Exception {
super.setUp();
project = createFreeStyleProject();
}


public void testGlobalPropertiesWithWORKSPACE() throws Exception {

final String testWorkspaceVariableName = "TEST_WORKSPACE";
final String testWorkspaceVariableValue = "${WORKSPACE}";
final String workspaceName = "WORKSPACE";

//A global node property TEST_WORKSPACE
DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = Hudson.getInstance().getGlobalNodeProperties();
globalNodeProperties.add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry(testWorkspaceVariableName, testWorkspaceVariableValue)));

EnvInjectJobProperty jobProperty = new EnvInjectJobProperty();
jobProperty.setOn(true);
jobProperty.setKeepBuildVariables(true);
jobProperty.setKeepJenkinsSystemVariables(true);
project.addProperty(jobProperty);

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 workspaceProcessed = envVars.get(workspaceName);
assertNotNull(workspaceProcessed);
String testWorkspaceProcessed = envVars.get(testWorkspaceVariableName);
assertNotNull(testWorkspaceProcessed);

assertEquals(workspaceProcessed, testWorkspaceProcessed);
}
}

0 comments on commit be86097

Please sign in to comment.