1

A couple years ago I was on a project and we had Ansible playbooks running with freestyle Jenkins jobs by using PYTHONUNBUFFERED=1 as an environment variable so that we can see output in realtime, it worked great, it was really useful. Then one day, it stopped working, we tried to fix it but never spent enough time figuring out "what changed" and had other priorities.

I am on another project now with the same technique, only differences are that we have newer Python, Jenkins and Ansible now. I just tried setting PYTHONUNBUFFERED=1 again but no luck, the long running Ansible task that is using the shell module buffers all the output and displays it only after the command has returned.

I have also tried PYTHONBUFFERED=0, and I tried prefixing the playbook run like PYTHONUNBUFFERED=1 ansible-playbook ... and also using the pipeline setting environment to set it and verified with a printenv but still no luck.

Looking for suggestions on what to try next.

How do I get Jenkins 2.233, Python 2.7.16 and Ansible 2.8.1 to not buffer the output for Ansible shell tasks?

p.s. For reference, other engineers use this technique too: e.g 1. https://coderwall.com/p/d5zqla/unbuffered-output-with-ansible-in-jenkins 2. https://blog.deimos.fr/2016/01/07/ansible-color-and-buffer-fix-on-jenkins/

Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
  • 2
    Your environment variable is passing through a lot of different pieces, Jenkins, Python, Ansible. I'd make sure that the environment variable is being passed down through the levels faithfully. Find and print it at each level. – Frank Merrow Apr 30 '20 at 02:19
  • I like that idea, thanks Frank, will try soon! – Elijah Lynn Apr 30 '20 at 04:17
  • 1
    Note to self: I think another good debug step is to try a freestyle job, our current jobs are pipeline jobs. – Elijah Lynn Apr 30 '20 at 18:35
  • Another crumb to explore: https://stackoverflow.com/questions/37123805/unbuffered-python-subrocess-pipe (Unbuffered Python Subrocess PIPE) – Elijah Lynn Apr 30 '20 at 18:37
  • It's a good question, still very relevant 3 years later. I'm also looking how to get realtime output for long running **Pipeline Shell** steps in Jenkins console. Haven't find resolution yet... – Noam Manos Jun 09 '23 at 20:26

0 Answers0