Skip to content
Permalink
Browse files

Fix for JENKINS-24467 and new test case

  • Loading branch information...
Rob Langley authored and MarkEWaite committed Sep 2, 2014
1 parent f654185 commit 392df636ee4e252ced10ab81f8fa9005c045d867
@@ -266,8 +266,8 @@ private static void addEnvironmentContributingActionsValues(EnvVars env, Abstrac
if (buildActions != null) {
for (Action action : buildActions) {
// most importantly, ParametersAction will be processed here (for parameterized builds)
if (action instanceof EnvironmentContributingAction) {
EnvironmentContributingAction envAction = (EnvironmentContributingAction) action;
if (action instanceof ParametersAction) {
ParametersAction envAction = (ParametersAction) action;
envAction.buildEnvVars(b, env);
}
}
@@ -5,6 +5,7 @@
import com.google.common.collect.Lists;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.Axis;
import hudson.matrix.AxisList;
import hudson.matrix.MatrixBuild;
@@ -18,6 +19,7 @@
import hudson.plugins.git.extensions.impl.*;
import hudson.plugins.git.util.BuildChooserContext;
import hudson.plugins.git.util.BuildChooserContext.ContextCallable;
import hudson.plugins.git.util.GitUtils;
import hudson.plugins.parameterizedtrigger.BuildTrigger;
import hudson.plugins.parameterizedtrigger.ResultCondition;
import hudson.remoting.Callable;
@@ -44,6 +46,8 @@

import java.io.File;
import java.io.IOException;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.*;

/**
@@ -1322,6 +1326,77 @@ public void testPolling_environmentValueInBranchSpec() throws Exception {
assertFalse("No changes to git since last build, thus no new build is expected", project.poll(listener).hasChanges());
}

private final class FakeParametersAction implements EnvironmentContributingAction, Serializable {
// Test class for testPolling_environmentValueAsEnvironmentContributingAction test case
final ParametersAction m_forwardingAction;

public FakeParametersAction(StringParameterValue params) {
this.m_forwardingAction = new ParametersAction(params);
}

public void buildEnvVars(AbstractBuild<?, ?> ab, EnvVars ev) {
this.m_forwardingAction.buildEnvVars(ab, ev);
}

public String getIconFileName() {
return this.m_forwardingAction.getIconFileName();
}

public String getDisplayName() {
return this.m_forwardingAction.getDisplayName();
}

public String getUrlName() {
return this.m_forwardingAction.getUrlName();
}

public List<ParameterValue> getParameters() {
return this.m_forwardingAction.getParameters();
}

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
}

private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
}

private void readObjectNoData() throws ObjectStreamException {
}
}

/**
* Test for JENKINS-24467.
*
* @throws Exception
*/
public void testPolling_environmentValueAsEnvironmentContributingAction() throws Exception {
// create parameterized project with environment value in branch specification
FreeStyleProject project = createFreeStyleProject();
GitSCM scm = new GitSCM(
createRemoteRepositories(),
Collections.singletonList(new BranchSpec("${MY_BRANCH}")),
false, Collections.<SubmoduleConfig>emptyList(),
null, null,
Collections.<GitSCMExtension>emptyList());
project.setScm(scm);

// Inital commit and build
commit("toto/commitFile1", johnDoe, "Commit number 1");
final String brokenPath = "\\broken/path\\of/doom";
final StringParameterValue real_param = new StringParameterValue("MY_BRANCH", "master");
final StringParameterValue fake_param = new StringParameterValue("PATH", brokenPath);

final Action[] actions = {new ParametersAction(real_param), new FakeParametersAction(fake_param)};

FreeStyleBuild first_build = project.scheduleBuild2(0, new Cause.UserCause(), actions).get();
assertBuildStatus(Result.SUCCESS, first_build);

Launcher launcher = workspace.createLauncher(listener);
final EnvVars environment = GitUtils.getPollEnvironment(project, workspace, launcher, listener);

assertNotSame("Enviroment path should not be broken path", environment.get("PATH"), brokenPath);
}

private void setupJGit(GitSCM git) {
git.gitTool="jgit";
jenkins.getDescriptorByType(GitTool.DescriptorImpl.class).setInstallations(new JGitTool(Collections.<ToolProperty<?>>emptyList()));

0 comments on commit 392df63

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