Arpit Pruthi
Arpit Pruthi

Reputation: 169

Passing variable in airflow macros

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.

Upvotes: 2

Views: 1849

Answers (1)

Elad Kalif
Elad Kalif

Reputation: 16139

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

Upvotes: 3

Related Questions