开发者

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 i开发者_开发知识库f 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 :)


@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%


Calling the .bat file from your post-commit hook doesn't require any magic.

Rename the post-commit hook template in .git/hooks/post-commit.sample to .git/hooks/post-commit and call the batch file within by simply writing the name of the batch file:

#!/bin/sh
path/to/batchfile.bat

Please note that the working directory for the git hook is the root directory of your repo. If you use relative paths to your .bat file, you have to take this into account.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜