windows服务器下git server搭建和自动部署
2015-01-09 TECH auto deploy git gitblit groovy
一、git server: gitblit
gitblit一个基于java的适用于小规模git库的git server,有win/mac/linux等各种版本
下载解压即可使用,主配置文件 D:\gitblit\data\gitblit.properties (下面都假设gitblit安装目录为D:\gitblit)
几个需要关注的配置
... #--git库集中存放的根目录 git.repositoriesFolder = E:\git ... #--git库web管理端口 server.httpPort = 8080 ... #--多IP时指定使用的IP server.httpBindInterface = 192.168.0.222 ...
安装为系统服务(installService.cmd)需要先修改一下:
1)、SET ARCH=xx,根据系统环境修改
2)、然后追加一行: SET CD=D:\gitblit 指定gitblit目录
3)、–StopParams=”xxx xxx xxx” ^ 改为 –StopParams=”” ^
安装后启动”gitblit”服务,http://192.168.0.222:8080/ 默认用户名密码admin:admin
二、自动部署
git自动部署方案基本都是用hook方式实现的,gitblit的push hooks全都放在 D:\gitblit\data\groovy\,其中 localclone.groovy 用以clone git库到本地指定的目录,可以拿来参考,稍加修改即可实现自动部署
... //--clone的目标根目录和子目录-- def rootFolder = 'D:/wwwroot/test.com' def subFolder = 'git_source' ... //--clone的目标子目录: git_source-- def destinationFolder = new File(rootFolder, subFolder) ... git.repository.close() //--删除.git目录,防止敏感信息泄漏-- def gitpath = new File( rootFolder + subFolder + '/.git' ) gitpath.deleteDir() ...
以上代码实现用户push后,代码自动clone到 D:/wwwroot/test.com/git_source/,并删除D:/wwwroot/test.com/git_source/.git/ 目录
注:
windows下如果subFolder为空,每次clone触发都会删除原rootFolder,再新建,然后再clone进去,
这样web目录的安全权限设置会丢失,所以用clone到子目录就是为了iis目录的权限继承
暂无评论