Rahul Chauhan
Rahul Chauhan

Reputation: 33

Jenkins job is marked as Failed, even though there are no errors in bat file execution

I am calling a bat file from jenkins, in Execute Windows batch command block.

Below are the commands in this block.

setlocal enabledelayedexpansion set PATH=C:\OracleATS\openScript;%PATH% cd C:\OracleATS\openScript call runScript.bat D:\Sanity\credit_card.jwg -batchId 235 echo "done"

After printing "done" on the console, the job status is marked as failed, even though there are no errors while running the batch file.

Can someone please help?

Upvotes: 1

Views: 5546

Answers (1)

dge
dge

Reputation: 3075

Jenkins evaluates the variable ERRORLEVEL for success/failure on batch jobs. ERRORLEVEL contains the returncode last command run.

That means, if you want to catch real errors, you need to implement the error handling yourself in the batch, because without - only the success/failure of the last command is evaluated by jenkins and there might be valid return codes > 0 which jenkins evaluates to failure.

try echo Errorlevel: %ERRORLEVEL% to see what you got at the end. You can do set ERRORLEVEL=0 to have the job always success, however best practice would be to do proper error handling.

Upvotes: 4

Related Questions