Making a job fail in jenkins

Viewed 16270

This question might sound weird, but how do I make a job fail?

I have a python script that compiles few files using scons, and which is running as a jenkins job. The script tests if the compiler can build x64 or x86 binaries, I want the job to fail if it fails to do one of these.

For instance: if I'm running my script on a 64-bit system and it fails to compile a 64-bit. Is there something I can do in the script that might cause to fail?

4 Answers

I came across this as a noob and found the accepted answer is missing something if you're running python scripts through a Windows batch shell in Jenkins.

In this case, Jenkins will only fail if the very last command in the shell fails. So your python command may fail but if there is another line after it which changes directory or something then Jenkins will believe the shell was successful.

The solution is to check the error level after the python line:

if %ERRORLEVEL% NEQ 0 (exit)

This will cause the shell to exit immediately if the python line fails, causing Jenkins to be marked as a fail because the last line on the shell failed.

Related