2025 Airflow 峰會將於 10 月 07-09 日舉行。立即註冊以獲取早鳥票!

匯出可供 Operator 使用的動態環境變數

airflow_local_settings.py 中定義的 get_airflow_context_vars 返回的鍵值對會被注入到預設的 Airflow 上下文環境變數中,這些變數在執行任務時可作為環境變數使用。請注意,鍵和值都必須是字串。

dag_idtask_idexecution_datedag_run_iddag_ownerdag_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"}

有關如何配置本地設定的詳細資訊,請參閱配置本地設定

此條目是否有幫助?