3
votes

I am testing out "Jenkins ver. 2.89.4" in Windows10 Machine and I have configured a simple job to test out few things. Under Build section in Jenkins, I have used "Execute Windows Batch Command" and used the following two commands. Both the below commands executes fine in the command prompt but however the Jenkins Build job keeps getting failed with Exit 1 state.

date
echo "SampleBuild job completed successfully."

Couldn't able to get the reason for the failure. And the following is what we see in console output.

Started by user Administrator Building in workspace C:\ProgramData\Jenkins\workspace\SampleBuildJob [SampleBuildJob] $ cmd /c call C:\WINDOWS\TEMP\jenkins6658106255890809140.bat

C:\ProgramData\Jenkins\workspace\SampleBuildJob>date
The current date is: Fri 02/23/2018 
Enter the new date: (mm-dd-yy) 
C:\ProgramData\Jenkins\workspace\SampleBuildJob>echo "SampleBuild job completed successfully." 
"SampleBuild job completed successfully."

C:\ProgramData\Jenkins\workspace\SampleBuildJob>exit 1 
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

Can anyone tell me, what am I missing?

3
Please add the /Toption to the date command to suppress it asking for setting the new date on the command line. Maybe that`s the reason for your failing command. - vre
You do not want to use a command that is going to prompt for input. date /T will suppress the output. The other option is echo %date% - David

3 Answers

2
votes

Try to add (call ) to end of your Batch Command.

This will clear the errorlevel environment variable, there for force the build result to be successful.

If you want to check a specific command's result to determine the build result. Let's say you want to check dates command.

(dates) || (exit %errorlevel% )

This will fail the build if error happens in the first command.
or

(dates) && (echo "command executed succesfully!")

This will show the message only when the first command successfully executed.

Then with the changed command, you do not need (call ) any more.

1
votes

This windows batch script will work:

echo %DATE%
echo %Time%
echo "command executed succesfully!"
0
votes

The windows batch script show the same error to me. Finally i have added exit 0 at the end it worked