How To Use Git Hooks To Automatically Deploy Apps

How To Use Git Hooks To Automatically Deploy Apps

Probably the most common version control system, used by developers today is git. Whether that is a self hosted server (like Gogs), a bare repo (git init) or with GitHub, most developers intuitively seem to choose for git as their version control system of choice. I try to store all my projects in local git repos and some of them make it to GitHub, while many of them don’t. When it comes to deployment of apps to TIBCO Cloud Integration, I do many updates per day so I wanted an easy way to not only store my latest source but deploy them right after.

Enter git hooks …

Git hooks are scripts that are executed when a specific event occurs in your repository. With those scripts you can configure what needs to happen at commits (or right before), before patches, etc. Atlassian has quite a good tutorial on those hooks.

For my use case I created a Git post-commit script to deploy my Node.js apps directly to TIBCO Cloud Integration either using an environment variable or using a more interactive mode. The interactive mode gives me a ‘yes/no’ option after committing my new code to the repo, in case I have a fear of commitment ;-)

To get started, Windows only for now, clone my repo and copy the post-commit and post-commit.ps1 files to your repo’s root .git/hooks directory. It’s probably not a great idea to actually clone the repo into the internals of your repo.

Change the location of the tibcli executable in the post-commit.ps1 file on line 5 to where you keep the executable

Select the mode you want to have by either commenting or uncommenting the mode on line 58 and 59 of the post-commit file.

Let me know your thoughts, concerns and suggestions!

Let's connect

If you have any questions or comments, feel free to drop me a note on Twitter!