UPDATE: guard clause throws LocalJumpError. Changed to simple if block Context: I needed our hudson CI builds to auto-fire when a developer pushes their code changes to our canonical/upstream git repositories. In your .git/hooks/post-receive file place the file code (FULL CODE):
| |
EXPLAINING EACH LINE: I avoid writing bash scripts in default bash if I can. This is for a Ruby on Rails app, so I decided to write it in Ruby.
| |
The while loop checks to make sure there are values in STDIN (by default they are rev_old, rev_new, and ref).
| |
I put an if statement block:
| |
to make sure I only fire the build if it is the master branch. Set the URL for the app you want to build:
| |
Add a little text to notify the user what is going on (always a good idea):
| |
And finally all the url with wget and feeding any response to the black hole that is /dev/null
:
| |
IMPORTANT: Don’t forget to run:
| |
so that the file can be run Some Gotchas: 1. If you are going to a url that has http basic authentication like my actual script does, you can pass the username and password like you normally would in an HTTP call:
| |
2. If you are doing an https call with a self-signed certificate, wget will complain. You can add the --no-check-certificate argument to wget to bypass certificate validation against local certificate caches:
| |