Skip to content

Commit 78b137d

Browse files
authored
Merge pull request #206 from abayer/jenkins-45575-jenkins-49679
[JENKINS-45575, JENKINS-49679] Test multiple assignment CPS fixes
2 parents 57bda81 + 0c4b3d9 commit 78b137d

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
buildPlugin(jenkinsVersions: [null, '2.60.3', '2.73.1'])
1+
buildPlugin(jenkinsVersions: [null, '2.73.3'])

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<git-plugin.version>3.1.0</git-plugin.version>
6969
<workflow-support-plugin.version>2.17</workflow-support-plugin.version>
7070
<scm-api-plugin.version>2.0.8</scm-api-plugin.version>
71-
<groovy-cps.version>1.22</groovy-cps.version>
71+
<groovy-cps.version>1.23</groovy-cps.version>
7272
<jenkins-test-harness.version>2.33</jenkins-test-harness.version>
7373
</properties>
7474
<dependencies>

src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,46 @@ public void variableDecl() throws Exception {
423423
p.setDefinition(new CpsFlowDefinition("String foo", true));
424424
jenkins.buildAndAssertSuccess(p);
425425
}
426+
427+
@Issue("JENKINS-45575")
428+
@Test
429+
public void multipleAssignmentInSandbox() throws Exception {
430+
WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p");
431+
job.setDefinition(new CpsFlowDefinition("def (a, b) = ['first', 'second']\n" +
432+
"def c, d\n" +
433+
"(c, d) = ['third', 'fourth']\n" +
434+
"assert a+b+c+d == 'firstsecondthirdfourth'\n", true));
435+
jenkins.buildAndAssertSuccess(job);
436+
}
437+
438+
@Issue("JENKINS-45575")
439+
@Test
440+
public void multipleAssignmentOutsideSandbox() throws Exception {
441+
WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p");
442+
job.setDefinition(new CpsFlowDefinition("def (a, b) = ['first', 'second']\n" +
443+
"def c, d\n" +
444+
"(c, d) = ['third', 'fourth']\n" +
445+
"assert a+b+c+d == 'firstsecondthirdfourth'\n", false));
446+
jenkins.buildAndAssertSuccess(job);
447+
}
448+
449+
@Issue("JENKINS-49679")
450+
@Test
451+
public void multipleAssignmentFunctionCalledOnce() throws Exception {
452+
WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p");
453+
job.setDefinition(new CpsFlowDefinition("alreadyRun = false\n" +
454+
"def getAandB() {\n" +
455+
" if (!alreadyRun) {\n" +
456+
" alreadyRun = true\n" +
457+
" return ['first', 'second']\n" +
458+
" } else {\n" +
459+
" return ['bad', 'worse']\n" +
460+
" }\n" +
461+
"}\n" +
462+
"def (a, b) = getAandB()\n" +
463+
"def c, d\n" +
464+
"(c, d) = ['third', 'fourth']\n" +
465+
"assert a+b+c+d == 'firstsecondthirdfourth'\n", true));
466+
jenkins.buildAndAssertSuccess(job);
467+
}
426468
}

0 commit comments

Comments
 (0)