I'm very new to Airflow, I wonder if I execute a bash operator, how can we get the console output of that Operator? I'm wondering does setting xcom_push = true solve the problem?
I'd very glad of anyone can answer this :)
I'm very new to Airflow, I wonder if I execute a bash operator, how can we get the console output of that Operator? I'm wondering does setting xcom_push = true solve the problem?
I'd very glad of anyone can answer this :)
If xcom_push is True, only the last line written to stdout will also be pushed to an XCom when the bash command completes.
Related source code: https://github.com/apache/airflow/blob/1.10.11/airflow/operators/bash_operator.py#L167-L168
To add to @kaxil's answer (as I don't have enough reputation to comment on his answer):
If your bash_command returns multiple lines that you want to include in xcom then add this to return everything on one line:
bash_command="<COMMAND> | tr '\n' '||'",
For those using Airflow 2+, BashOperator now returns the entire output (source), not just the last line and does not require specifying do_xcom_push (new name in 2+ instead of xcom_push), as it is true by default.