BashOperator¶
Use the BashOperator
to execute
commands in a Bash shell.
run_this = BashOperator(
task_id='run_after_loop',
bash_command='echo 1',
dag=dag,
)
Templating¶
You can use Jinja templates to parameterize the
bash_command
argument.
also_run_this = BashOperator(
task_id='also_run_this',
bash_command='echo "run_id={{ run_id }} | dag_run={{ dag_run }}"',
dag=dag,
)
Troubleshooting¶
Jinja template not found¶
Add a space after the script name when directly calling a Bash script with
the bash_command
argument. 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)