Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
ParametersDefinitionProperty not set when the first build begins.
Browse files Browse the repository at this point in the history
Without JENKINS-27295, this makes it awkward to have a default parameter value.
  • Loading branch information
jglick committed Oct 26, 2015
1 parent c621774 commit 4320015
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -35,6 +35,7 @@
import jenkins.branch.BranchSource;
import jenkins.branch.DefaultBranchPropertyStrategy;
import jenkins.plugins.git.GitSCMSource;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.steps.StepConfigTester;
Expand Down Expand Up @@ -75,9 +76,10 @@ public class JobPropertyStepTest {
@Issue("JENKINS-30206")
@Test public void useParameter() throws Exception {
sampleRepo.init();
ScriptApproval.get().approveSignature("method groovy.lang.Binding hasVariable java.lang.String"); // TODO add to generic whitelist
sampleRepo.write("Jenkinsfile",
"properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'StringParameterDefinition', name: 'myparam', defaultValue: 'default value']]]])\n" +
"echo \"received ${myparam}\"");
"echo \"received ${binding.hasVariable('myparam') ? myparam : 'undefined'}\"");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "--all", "--message=flow");
WorkflowMultiBranchProject mp = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
Expand All @@ -87,7 +89,8 @@ public class JobPropertyStepTest {
r.waitUntilNoActivity();
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
r.assertLogContains("received default value", b1);
// TODO not all that satisfactory since it means you cannot rely on a default value; would be a little easier given JENKINS-27295
r.assertLogContains("received undefined", b1);
WorkflowRun b2 = r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("myparam", "special value"))));
assertEquals(2, b2.getNumber());
r.assertLogContains("received special value", b2);
Expand Down

0 comments on commit 4320015

Please sign in to comment.