Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[FIXED JENKINS-30910] Build environment should include parameters.
- Loading branch information
|
@@ -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; |
|
@@ -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 |
|
|
|
@@ -84,17 +84,19 @@ |
|
|
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); |
|
|