8

I've been able to successfully render Jinja Templates using the function within the BaseOperator, render_template.

My question is does anyone know the requirements to get rendered strings into the UI under the Rendered or Rendered Template tab?

Referring to this tab in the UI: Referring to this tab in the UI

Any help or guidance here would be appreciated.

tobi6
  • 8,033
  • 6
  • 26
  • 41
dillon
  • 125
  • 2
  • 2
  • 6

1 Answers1

9

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.

tobi6
  • 8,033
  • 6
  • 26
  • 41