导出可供操作员使用的动态环境变量
在 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"}
详见 配置本地设置 了解如何配置本地设置的细节。