Skip to content
Permalink
Browse files
[JENKINS-42499] Testing the fix.
  • Loading branch information
jglick committed Aug 24, 2017
1 parent 0102447 commit c7927ad10625904570cf9a80f2e7d8bcb03573cb
Showing with 26 additions and 0 deletions.
  1. +26 −0 src/test/java/org/jenkinsci/plugins/workflow/DynamicEnvironmentExpanderTest.java
@@ -25,6 +25,9 @@
package org.jenkinsci.plugins.workflow;

import hudson.EnvVars;
import hudson.model.EnvironmentContributor;
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.IOException;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
@@ -112,4 +115,27 @@ public DescriptorImpl() {
}
}

@Issue("JENKINS-42499")
@Test public void changingEnvironment() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo(/before VAR=$VAR/); " + EnvAdder.class.getCanonicalName() + ".value = 'after'; echo(/after VAR=$VAR/)", false));
WorkflowRun b = story.j.buildAndAssertSuccess(p);
story.j.assertLogContains("buildEnvironmentFor #1", b);
story.j.assertLogContains("before VAR=before", b);
story.j.assertLogContains("buildEnvironmentFor #2", b);
story.j.assertLogContains("after VAR=after", b);
}
});
}
@TestExtension("changingEnvironment") public static class EnvAdder extends EnvironmentContributor {
public static String value = "before";
private int count;
@Override public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) throws IOException, InterruptedException {
listener.getLogger().println("buildEnvironmentFor #" + count++);
envs.put("VAR", value);
}
}

}

0 comments on commit c7927ad

Please sign in to comment.