How can we perform git push using airflow dag?

Viewed 768

How can we perform git push using airflow dag? I am trying to perform git push for a specific branch via an airflow dag.

1 Answers

You can use BashOperator to perform any bash command (including git).

Apart from the link I already included, you can do something like this:

git_push_task = BashOperator(
    task_id='git_push_example',
    # "scripts" folder is under "/usr/local/airflow/dags"
    bash_command="scripts/git_push.sh",
    dag=dag
)

And inside scripts/git_push.sh something like:

cd folder/you/want/
git push

Remember to give it execution permissions with:

chmod +x scripts/git_push.sh

You can also check this post with very useful information.

Related