【问题标题】:Airflow XCom send variables inside templatingAirflow XCom 在模板中发送变量
【发布时间】:2018-03-14 01:29:45
【问题描述】:

我一直试图在 bash 脚本中将变量的内容发送到 Xcom。但是,我失败了。

test_bash = """
export test_val='123'
{{ ti.xcom_push(key='1',value=test_val) }}
echo $test_val
"""

bash_tash = BashOperator(
    task_id='test',
    bash_command=test_bash,
    retries=3,
    dag=dag)

在上面的代码中。当我试图拉它。我无法向 Xcom 发送任何内容。我试过用单引号发送文本,效果很好。

有没有办法将变量从 bash 脚本发送到 xcom?

【问题讨论】:

    标签: bash airflow templating


    【解决方案1】:

    您可以使用 BashOperator 以不同的方式提升您的价值:

    test_bash = """
    export test_val='123'
    echo $test_val
    """
    
    bash_task = BashOperator(
        task_id='test',
        bash_command=test_bash,
        xcom_push=True
        retries=3,
        dag=dag)
    

    然后你将值拉到另一个任务中。

    【讨论】:

      猜你喜欢
      • 2022-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多