Reputation: 707
I have the following case. In jenkins I have one build which is running on different envoironments. That's why I have build with parameters with two options PROD/TEST
. The build is invoking shell script with parameter PROD
or TEST
.
Here is example of the script A
which jenkins is invoking:
if %1%==TEST(
start F:\test.bat
)
The script A
itself is invoking another script - B
.
Here is example of script B
:
copy test.xt copyFolder\
The problem is that Jenkins only invoking the first script - A
- and the second script B
doesn't run.
Why does this happen?
Upvotes: 0
Views: 494
Reputation: 5504
You will need to call
the batch file, not start
it because it creates a new cmd.exe
instance, so it can run a called batch file asynchronously (as mentioned by jeb here):
if "%~1" == "TEST" (
call F:\test.bat
)
Here, I want to note some things:
%1%
will be interpreted as the first argument of the batch file (if any) and an extra percent-sign (%
). You probably wanted here the first argument, so I have replaced %1%
with %1
. If it is not this what you wanted, then replace it with your variable name, but remember that it should not start with a number!%1
was replaced by %~1
and quoted because:
%~1
means the first argument without any surrounding quotes.if
statement is always the best practice, but if there were quotes, the comparison would fail.==
, just to make the code clearer.For an one-liner, see aschipfl's comment, it is:
if /I "%~1"=="TEST" (call "F:\test.bat")
See call /?
and if /?
in cmd for more information about how these commands work.
Upvotes: 1