Azure git how to make Python script unbuffered

233 Views Asked by At

In an Azure git pipeline script (.yml), I can set up a Python task like this

- task: PythonScript@0
  displayName: "Run scripts"
  inputs:
    scriptSource: 'filePath'
    scriptPath: 'myscript.py'
    arguments: '$a $b $c'

But it doesn't print output until the task is complete. Normally I would call python -u myscript.py but there isn't an option to pass parameters to python itself; they can only be passed to the script. How can I set the input as unbuffered?

1

There are 1 best solutions below

0
twasbrillig On

Adding this to the Azure .yml script makes the output unbuffered, so that print statements appear right away:

variables:
- name: PYTHONUNBUFFERED
  value: PYTHONUNBUFFERED

It's an environment variable, and adding it here sets the value.