Airflow Jinja Rendered Template

試著忘記壹切 提交于 2019-12-04 05:58:33

If you are using templated fields in an Operator, the created strings out of the templated fields will be shown there. E.g. with a BashOperator:

example_task = BashOperator(
    task_id='task_example_task',
    bash_command='mycommand --date {{ task_instance.execution_date }}',
    dag=dag,
)

then the bash command would get parsed through the template engine (since a Jinja field is included) and later on you could see the result of this parsing in the web UI as you mentioned.

The fields must be templated, though. This can be seen in the code in the field templated_fields. For BashOperator (see code here https://github.com/apache/incubator-airflow/blob/master/airflow/operators/bash_operator.py) this is:

template_fields = ('bash_command', 'env')

Other fields in the BashOperator will not be parsed.

You can use macro commands (see here https://airflow.apache.org/code.html#macros) or information from xcom (see here https://airflow.apache.org/concepts.html?highlight=xcom#xcoms) in templated fields.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!