导出可供操作员使用的动态环境变量¶
定义在airflow_local_settings.py中的get_airflow_context_vars返回的键值对会被注入到默认的airflow上下文环境变量中,这些变量在运行任务时可以作为环境变量使用。请注意,键和值都必须是字符串。
dag_id, task_id, execution_date, dag_run_id,
dag_owner, dag_email 是保留关键字。
例如,在您的airflow_local_settings.py文件中:
def get_airflow_context_vars(context) -> dict[str, str]:
"""
:param context: The context for the task_instance of interest.
"""
# more env vars
return {"airflow_cluster": "main"}
有关如何配置本地设置的详细信息,请参阅配置本地设置。