@@ -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