SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы
НазадМетки: airflow apache airflow
Use the BashOperator to execute commands in a Bash shell.
airflow/example_dags/example_bash_operator.pyVIEW SOURCE
run_this = BashOperator(
task_id='run_after_loop',
bash_command='echo 1',
dag=dag,
)
You can use Jinja templates to parameterize the bash_command argument.
airflow/example_dags/example_bash_operator.pyVIEW SOURCE
also_run_this = BashOperator(
task_id='also_run_this',
bash_command='echo "run_id={{ run_id }} | dag_run={{ dag_run }}"',
dag=dag,
)
Add a space after the script name when directly calling a Bash script with the bash_commandargument. This is because Airflow tries to apply a Jinja template to it, which will fail.
t2 = BashOperator(
task_id='bash_example',
# This fails with `Jinja template not found` error
# bash_command="/home/batcher/test.sh",
# This works (has a space after)
bash_command="/home/batcher/test.sh ",
dag=dag)