I’m attempting to send the contents of a variable to Xcom within a bash script in my task, but I’m encountering difficulties. Here’s the relevant portion of my code:
task_a = BashOperator(
task_id="task_a",
bash_command=""" export hostname=$(hostname -i | awk '{print $1}')
&& echo "{{ ti.xcom_push(key='k1', value=hostname) }}"
&& sleep 100
&& echo "Command after task a XCom"
""",
dag=dag,
)
However, I’m encountering the following error: jinja2.exceptions.UndefinedError: ‘hostname’ is undefined. Iwant the bash script sends the Xcom to other tasks and then proceeds with additional works in parallel. How can I resolve this issue?”