Batch script is not executing another batch if I run from jenkins - batch-file

I have installed Jenkins 1.55 exe in windows environment. I have a build script*.bat) which internally calls another (.bat). While executing manually it is working fine but while trying in jenkins only first batch script is executing without triggering the second one and it is giving as success.
Is there any solution for this?
D:\Jenkins\workspace\9.0_TP_Build>cd D:\PortalScripts\9000 portal\
D:\PortalScripts\9xxx portal>WL9.0-TPRefresh-doPortalNightlyBuild2.bat ---> THis is the file i am executing
D:\PortalScripts\9xxx portal>cd d:\PortalScripts\axxx portal
D:\PortalScripts\9xxx portal>call WL-9000-TPRefresh-BuildPortal.bat a.x.x.x axxx axxx --> THis is the second file needs to be executed...but the below echo are from the first batc files...
D:\PortalScripts\9xxx portal>REM #echo off
D:\PortalScripts\9xxx portal>SET HR= 5

If you call a batch file from another, the first one will exit after executing the 2nd one, unless it is called with "call". For example:
call WL9.0-TPRefresh-doPortalNightlyBuild2.bat
instead of just:
WL9.0-TPRefresh-doPortalNightlyBuild2.bat
There is a similar question/answer here, with an example: Batch Closing before end of file?

Related

Issue executing multiple Batch files within main batch file

I have 3 batch files which consume a common variable-'target'. These batch files need to be executed one after the other. I am using one main batch file where I am trying to call these three batch files. But the execution stops right after first batch job is done. If I execute these batch jobs individually within that main batch file, they gets executed fine without any issue. Not sure what's missing here.
Main batch file (MainBatch.bat) contents:
set target=OHD121
CALL C:\Users\abc\x1.bat
pause
CALL C:\Users\abc\y1.bat
pause
CALL C:\Users\abc\z1.bat
pause
I figured the reason behind the issue. in my called bat files, I have another bat file for which I wasn't using call and that's why the control wasn't returning to original call action to perform subsequent steps.

Why can't we execute multiple statements of BigQuery in a batch file?

I have observed when we run a simple gsutil or bq statements in windows command prompt they will run successfully
ex 1 : gsutil cp Desktop\MyTraffic.csv gs://BI/
ex 2 : bq load --autodetect --replace --source_format=CSV myDataSet.myTable gs://BI/MyTraffic.csv
but if we run them both in using a batch file like 'runbq.bat' , only first statement will run and the command prompt will terminate immediately without any error
Even adding a pause statement between them won't hold the command prompt window
runbq.bat :
gsutil cp Desktop\MyTraffic.csv gs://BI/
pause
bq load --autodetect --replace --source_format=CSV myDataSet.myTable gs://BI/MyTraffic.csv
As mentioned by Aacini, when running a batch script within a "master" batch script, it is required to use the call command in order to pause the execution of the current batch file and wait until the called batch file completes; in this way the process can return and continue in the original flow. However, when the call command is not added, the original batch file stops and the called batch file starts executing without returning to the original flow.
Another possibility is to use the start command instead in case you don't want to lock the "master" script.

Unable to execute a .bat file in post build event command line

My post build command is
call "$(ProjectDir)MyFile.bat"
And getting build error:
Error 1 The command "call
C:\MyProject\MyFile.bat"
exited with code 1. C:\Program Files
(x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets 4548 5
What am I missing here? Working on TFS source code, is that the reason getting this error?
For testing in MyFile.bat the only code is mkdir MYTestFolder, but then I am also getting the same error.
It seems like the syntax of the call is correct. Therefore I believe it's failing inside the batch file. I suggest putting the first few lines of the batch to write the time into a log file, so you can confirm it's being called. Do this before any of the actual work, so it can be sure that the batch is being executed.
call "$(ProjectDir)MyFile.bat"
MyFile.bat
#echo off
echo time /t > MyTempFolderPath\logfile.txt
It is the code inside the batch file that is failing - what is it doing?
You have a few options:
a - I would use process monitor and watch process exits and see the status codes of whatever the batch file launches.
b - You could also try running the batch file from the same folder as msbuild and see if you get any errors
Ed

how to stop calling another batch script from main batch script if first calling batch script gives any error..?

I have one windows batch script where I am calling two other batch script. What I want - if my first batch gives any error it should not call second batch; rather it should immediately exit the main batch script. Here is my main batch file(main.bat) code:
echo.[INFO] Calling Joomla setup batch file
call joomla_setup.bat
echo.[INFO] Finished Joomla setup batch file execution
echo.[INFO] Calling Build and deploy setup batch file
call build_deploy.bat
echo.[INFO] Finished Build and deploy setup batch file execution
ECHO.&ECHO.Press any key to exit COSOMO installer.&PAUSE>NUL&GOTO:EOF
In this code, if joomla_setup.bat gives any error in execution I want main.bat not to call build_deploy.bat and exit immediately. Any quick and useful response would be appreciable.
call joomla_setup.bat || exit /b 255
Of course, that relies on joomla_setup.bat using exit codes to signal failure. If that's not the case it would be helpful to know how you would determine failure in your example.

Batch script stops after first call to other batch script

I'm attempting to execute a batch script that currently looks like this:
D:
cd D:My Documents\FtpSolution\Test
getftp.bat
call delimconvert.exe
call convert-to-xls.bat
However this stops dead after getftp.bat has run.
What am I doing wrong? It's important that these commands all run sequentially.
Use call:
Calls one batch program from another.
CALL [drive:][path]filename [batch-parameters]
batch-parameters Specifies any command-line information required by the
batch program.
If you invoke other batch files without call then control is passed to them but not back again (which is what call changes).
use start command to launch it in a new window.
start /wait getftp.bat
Try using "Goto :EOF" rather than "exit" at the end of the batch file that you're calling - in your case, the getftp.bat file...
That's what fixed mine - tested on Win10 enterprise.

Resources