Passing variable in airflow macros

Viewed 686

Please help me with {{ execution_date.subtract(hours = 5) }} Here instead of hardcoding 5, I want to pass it as a variable. I am not able to find a way to pass a variable and finally use the value of the variable.

1 Answers

You can use:

f'echo {{{{ execution_date.subtract(hours = {value}) }}}}'

Example with BashOperator:

value = 5 # This can be set dynamically
hello_my_task = BashOperator(
    task_id='my_task',
    bash_command=f'echo {{{{ execution_date.subtract(hours = {value}) }}}}',
    dag=dag,
)

enter image description here

Related