GIT: allow push to master only if build succeeds

18 Dec

It may be a requirement of companies, that the master and develop branch contains only code that is always compilable. Therefore we need to ensure that every push, or merge on a master branch results not in breaking the build of the application. This can be achieved with git-hook file that has the Name pre-commit and is copied into .git\hooks directory.

branch=$(git rev-parse --abbrev-ref HEAD)

if [ "master" != "$branch" ] && [ "develop" != "$branch" ]; then
    exit 0;

echo "To commit on a master or develop branch we need to check whether msbuild compiles successful."

"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" /consoleloggerparameters:"ErrorsOnly;PerformanceSummary"

if [ "$status" != "0" ]; then
    echo "Build failed. If you publish to the $branch branch you should ensure that the solution builds correctly"
exit $status
Leave a comment

Posted by on December 18, 2014 in C-Sharp, Git



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: