Skip to content

Commit

Permalink
[FIXED JENKINS-30910] Build environment should include parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Sep 17, 2016
1 parent 40be32c commit 219fde3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java
Expand Up @@ -33,13 +33,16 @@
import com.google.common.util.concurrent.SettableFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.AbortException;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.XmlFile;
import hudson.console.AnnotatedLargeText;
import hudson.console.LineTransformationOutputStream;
import hudson.model.Executor;
import hudson.model.Item;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Run;
Expand Down Expand Up @@ -336,6 +339,19 @@ public void doKill() {
// TODO CpsFlowExecution.onProgramEnd does some cleanup which we cannot access here; perhaps need a FlowExecution.halt(Throwable) API?
}

@Override public EnvVars getEnvironment(TaskListener listener) throws IOException, InterruptedException {
EnvVars env = super.getEnvironment(listener);
// TODO EnvironmentContributingAction does not support Job yet:
ParametersAction a = getAction(ParametersAction.class);
if (a != null) {
for (ParameterValue v : a) {
v.buildEnvironment(this, env);
}
}
EnvVars.resolve(env);
return env;
}

@GuardedBy("completed")
private void copyLogs() {
if (logsToCopy == null) { // finished
Expand Down
Expand Up @@ -84,17 +84,19 @@ public class WorkflowRunTest {
r.assertLogContains("hello\n", b1);
}

@Issue("JENKINS-30910")
@Test public void parameters() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo \"param=${PARAM}\"",true));
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("PARAM", null)));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("PARAM", "value"))));
r.assertLogContains("param=value", b);
r.assertLogContains("param=value", r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("PARAM", "value")))));
p.setDefinition(new CpsFlowDefinition("echo \"param=${env.PARAM}\"",true));
r.assertLogContains("param=value", r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("PARAM", "value")))));
}

@Test public void funnyParameters() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo \"a.b=${binding['a.b']}\"", /* TODO Script.binding does not work in sandbox */false));
p.setDefinition(new CpsFlowDefinition("echo \"a.b=${binding['a.b']}\"", true));
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("a.b", null)));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("a.b", "v"))));
r.assertLogContains("a.b=v", b);
Expand Down

0 comments on commit 219fde3

Please sign in to comment.