Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I run cmd from the git post-commit hook

I want to have a miniature ci loop on my private projects and was thinking if I could run msbuild inside a batfile I could have colorized feedback on the cmd window and automate the build. So if I could just trigger the bat from the post - commit hook I guess it would be possible. It can´t possible be a new idea but I can´t find any examples on google.

any input would be appreciated :)

like image 451
zzzuperfly Avatar asked Sep 13 '11 11:09

zzzuperfly


1 Answers

@eckes' answer was close but actually was running my bat/cmd files as if they were bash scripts. If you want to run them as batch files, here is what worked for me:

post-receive

#!/bin/sh
# important that it's got the .exe on the end!
cmd.exe /c "C:\path\to\somebatch.cmd"

somebatch.cmd

Here's some stuff/envrionment variables etc that you might find useful:

@echo off

:: read commit hook stdin data e.g. "aa45321… 68f7abf… refs/heads/master"
set /p OLDREV_NEWREV_REFNAME=

echo Directory of this script is %~dp0
echo Repository root is %CD%

set OLDREV=%OLDREV_NEWREV_REFNAME:~0,40%
echo OLDREV: %OLDREV%

set NEWREV=%OLDREV_NEWREV_REFNAME:~41,40%
echo NEWREV: %NEWREV%

set REFNAME=%OLDREV_NEWREV_REFNAME:~82,999%
echo REFNAME: %REFNAME%
like image 90
Duncan Smart Avatar answered Oct 03 '22 07:10

Duncan Smart