A
A
Alexey M.2015-10-07 11:02:56
Python
Alexey M., 2015-10-07 11:02:56

How to pass a return code from Python 3.X?

Good afternoon!
Can you please tell me how to get the return code from Python 3.4?
Actually, the python script is launched from the CI Jenkins command line, to which you subsequently need to pass the result of SUCCESS aka exit 0, or FAIL aka exit 1 to correctly mark the build (BUILD) with the corresponding success or error status. How can I do something I can't figure out?
try...except do not roll, intentionally tried to reproduce an error, it is impossible.
Using subprocess, etc. means for launching cmd, or something like: they don’t help either ... Before that, the script worked without questions on the first exception and all builds were marked as they should, and here the script is simple for 20 lines, everything works, but the builds are all successful for some reason.
raise SystemExit(1)
And how to pass the value of the errorlevel variable to the build result in order to use something like this:

Set errorlevel=%ResultFromPython%
if not errorlevel 0 exit 1
?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey M., 2015-10-13
@lnl

The issue is resolved, Jenkins cant ... Python issues the correct return code, but Jenkins completely refuses to accept it. I solved the issue by assigning the value 0/1 to the variable from a temporary file, which is subsequently overwritten. If 1, then exit 1, otherwise exit 0

A
Andrey K, 2015-10-07
@mututunus

import sys
sys.exit(1)

S
Sly_tom_cat ., 2015-10-07
@Sly_tom_cat

$ cat exit.py 
#!/usr/bin/env python3
if __name__ == '__main__':
  exit(1)

$ python3 exit.py 
$ echo $?
1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question