When I run a command from the CMD directly it works perfectly fine but when run the same command in a batch file (or Jenkins using batch) it gives me a different result and I dont understand why.
To explain it simple, I'm running command below to search for a literal string within a log file:
findstr /C:"MY STRING WITH A %variable%" M:\Logs\output.log
If I check the %ERRORLEVEL% of the result it shows the expected values (0 = found the string or 1 = didnt find it)
However, when I run the same line from a batch file, even from Jenkins, the result is always 0, even though the string is not present in the log, the %ERRORLEVEL% is always 0.
This is the portion of the batch file which includes the command:
if %COUNTER% ==1 (
if not exist M:\Logs\current_bak (
ROBOCOPY "M:\Logs\tkcurrent" "M:\Logs\tkcurrent_bak"
REN "M:\Logs\current" "M:\Logs\current_bak"
MKDIR M:\Logs\current
echo Folders have been backed up
) else (
echo Back up folders are already in place )
findstr /C:"MY STRING WITH A %variable%" M:\Logs\output.log
if %ERRORLEVEL% == 0 (
echo Process has already being kicked off for the files with date %YYMMDD%, skipping it...
echo Download and backup compleated
exit /b 0 )
else (
echo Triggering next Jenkins Job:
curl -I http://<user>:<token>@remoteserver.domain.com:<port>/job/Hello_World/build?token=hello_world
exit /b 0 )
)
Has someone experienced this in the past or can guide me better on what I'm doing wrong or not understanding?
Thanks a lot!