Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get python print result in jenkins console output

Tags:

python

jenkins

I have a Python script print strings. Now when run it in Jenkins I didn't see the printed strings in Jenkins Builds' Console Output.

Anyway to achieve that?

like image 653
Grace Avatar asked Apr 03 '14 01:04

Grace


People also ask

Where is Jenkins console output stored?

On Windows, Jenkins log files are stored as jenkins. out (console output logs) and jenkins. err (error logs) in the Jenkins home folder. Note: Jenkins logs may be stored in the Jenkins installation folder in Program Files on some Windows systems.


3 Answers

Try using -u (unbuffered) option when running the python script.

python -u my_script.py

like image 146
gh0st Avatar answered Oct 18 '22 22:10

gh0st


Any output to stdout from a process spawned by Jenkins should be captured by Console Output. One caveat is that it won't be displayed until a newline character is printed, so make sure your lines are terminated.

If you are launching python in some weird way that dis-associates it from Jenkins parent process, then I can't help you.

like image 4
Slav Avatar answered Oct 18 '22 22:10

Slav


I believe that what you need to do is a flush, try:

import sys
sys.stdout.flush()

It should help.

like image 2
Suryavanshi Avatar answered Oct 18 '22 22:10

Suryavanshi