2424
2525package org .jenkinsci .plugins .workflow .steps ;
2626
27+ import hudson .Functions ;
2728import org .jenkinsci .plugins .workflow .cps .CpsFlowDefinition ;
2829import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
2930import org .jenkinsci .plugins .workflow .job .WorkflowRun ;
@@ -46,19 +47,19 @@ public class EnvStepRunTest {
4647 WorkflowJob p = story .j .jenkins .createProject (WorkflowJob .class , "p" );
4748 p .setDefinition (new CpsFlowDefinition (
4849 "env.CUSTOM = 'initial'\n " +
49- "env.FOOPATH = '/opt/foos'\n " +
50+ "env.FOOPATH = node {isUnix() ? '/opt/foos' : 'C: \\ \\ foos'} \n " +
5051 "env.NULLED = 'outside'\n " +
5152 "node {\n " +
52- " withEnv(['CUSTOM=override', 'NOVEL=val', 'BUILD_TAG=custom', 'NULLED=', 'FOOPATH+BALL=/opt/ball']) {\n " +
53- " sh 'echo inside CUSTOM=$CUSTOM NOVEL=$NOVEL BUILD_TAG=$BUILD_TAG NULLED=$NULLED FOOPATH=$FOOPATH:'\n " +
53+ " withEnv(['CUSTOM=override', 'NOVEL=val', 'BUILD_TAG=custom', 'NULLED=', isUnix() ? 'FOOPATH+BALL=/opt/ball' : 'FOOPATH+BALL=C: \\ \\ ball']) {\n " +
54+ " isUnix() ? sh( 'echo inside CUSTOM=$CUSTOM NOVEL=$NOVEL BUILD_TAG=$BUILD_TAG NULLED=$NULLED FOOPATH=$FOOPATH:') : bat('echo inside CUSTOM=%CUSTOM% NOVEL=%NOVEL% BUILD_TAG=%BUILD_TAG% NULLED=%NULLED% FOOPATH=%FOOPATH%;') \n " +
5455 " echo \" groovy NULLED=${env.NULLED}\" \n " +
5556 " }\n " +
56- " sh 'echo outside CUSTOM=$CUSTOM NOVEL=$NOVEL NULLED=outside:' \n " +
57- "}" ));
57+ " isUnix() ? sh( 'echo outside CUSTOM=$CUSTOM NOVEL=$NOVEL NULLED=outside') : bat('echo outside CUSTOM=%CUSTOM% NOVEL=%NOVEL% NULLED=outside') \n " +
58+ "}" , true ));
5859 WorkflowRun b = story .j .assertBuildStatusSuccess (p .scheduleBuild2 (0 ));
59- story .j .assertLogContains ("inside CUSTOM=override NOVEL=val BUILD_TAG=custom NULLED= FOOPATH=/opt/ball:/opt/foos:" , b );
60+ story .j .assertLogContains (Functions . isWindows () ? "inside CUSTOM=override NOVEL=val BUILD_TAG=custom NULLED= FOOPATH=C: \\ ball;C: \\ foos;" : "inside CUSTOM=override NOVEL=val BUILD_TAG=custom NULLED= FOOPATH=/opt/ball:/opt/foos:" , b );
6061 story .j .assertLogContains ("groovy NULLED=null" , b );
61- story .j .assertLogContains ("outside CUSTOM=initial NOVEL= NULLED=outside: " , b );
62+ story .j .assertLogContains ("outside CUSTOM=initial NOVEL= NULLED=outside" , b );
6263 }
6364 });
6465 }
@@ -69,10 +70,10 @@ public class EnvStepRunTest {
6970 WorkflowJob p = story .j .jenkins .createProject (WorkflowJob .class , "p" );
7071 p .setDefinition (new CpsFlowDefinition (
7172 "parallel a: {\n " +
72- " node {withEnv(['TOOL=aloc']) {semaphore 'a'; sh 'echo TOOL=$TOOL'}}\n " +
73+ " node {withEnv(['TOOL=aloc']) {semaphore 'a'; isUnix() ? sh( 'echo TOOL=$TOOL') : bat('echo TOOL=%TOOL%') }}\n " +
7374 "}, b: {\n " +
74- " node {withEnv(['TOOL=bloc']) {semaphore 'b'; sh 'echo TOOL=$TOOL'}}\n " +
75- "}" ));
75+ " node {withEnv(['TOOL=bloc']) {semaphore 'b'; isUnix() ? sh( 'echo TOOL=$TOOL') : bat('echo TOOL=%TOOL%') }}\n " +
76+ "}" , true ));
7677 WorkflowRun b = p .scheduleBuild2 (0 ).getStartCondition ().get ();
7778 SemaphoreStep .waitForStart ("a/1" , b );
7879 SemaphoreStep .waitForStart ("b/1" , b );
@@ -92,7 +93,7 @@ public class EnvStepRunTest {
9293 p .setDefinition (new CpsFlowDefinition (
9394 "def show(which) {\n " +
9495 " echo \" groovy ${which} ${env.TESTVAR}:\" \n " +
95- " sh \" echo shell ${which} \\ $TESTVAR:\" \n " +
96+ " isUnix() ? sh( \" echo shell ${which} \\ $TESTVAR:\" ) : bat( \" echo shell ${which} %TESTVAR%: \" ) \n " +
9697 "}\n " +
9798 "node {\n " +
9899 " withEnv(['TESTVAR=val']) {\n " +
@@ -101,7 +102,7 @@ public class EnvStepRunTest {
101102 " show 'after'\n " +
102103 " }\n " +
103104 " show 'outside'\n " +
104- "}" ));
105+ "}" , true ));
105106 WorkflowRun b = p .scheduleBuild2 (0 ).getStartCondition ().get ();
106107 SemaphoreStep .waitForStart ("restarting/1" , b );
107108 }
@@ -128,7 +129,7 @@ public class EnvStepRunTest {
128129 "node {\n " +
129130 " withEnv(['A=one']) {\n " +
130131 " withEnv(['B=two']) {\n " +
131- " sh 'echo A=$A B=$B'\n " +
132+ " isUnix() ? sh( 'echo A=$A B=$B') : bat('echo A=%A% B=%B%') \n " +
132133 " }\n " +
133134 " }\n " +
134135 "}" ));
0 commit comments