
将如下shell脚本保存为 pre-push 文件,注意没有后缀,然后拷贝到工程里 git/hooks/ 目录下为有读写权限的用户建立一个分组。根据你的 *** 作系统,你可以用groupadd命令来实现,用vigr来编辑分组文件,或者直接编辑/etc/group文件。在最后,你会在/etc/group文件中看到如下一行
1
repogroup::10005:marry,john,violet
其中,repogroup是准许接入这个仓库的组的名字。10005是一个独一无二的分组识别数字,marry,john,violet则是获准接入这个仓库的用户。
决定Git仓库的路径。它既可以放在你的home路径下(eg /home/yourname/gitroot),也可以放在一个专用的路径下(eg /var/gitroot)
配置权限,让Git用户可以访问这个目录
1
2
chmod g+rx /path-to/gitroot
chown :grouprepo /path-to/gitroot
建立新的Git仓库,叫做newrepo
1
2
cd /path-to/gitroot
git init --bare newrepogit
建立路径认证,以允许用户组访问,同时有针对性的设置Git
1
2
3
4
5
cd newrepogit
chown -R :grouprepo
git config coresharedRepository group
find -type d -print0 | xargs -0 chmod 2770
find -type f -print0 | xargs -0 chmod g=u
设置提交(commit)的email通知(commit是一条命令),这样当有新的修改提交到仓库的时候,开发者们将会收到一封关于修改内容一览的电子邮件。
1
2
3
4
5
6
7
echo 'One-line project description' >description
git config --local hooksmailinglist email-a@examplecom<script cf-hash="f9e31" type="text/javascript">
/ <![CDATA[ /!function(){try{var t="currentScript"in documentdocumentcurrentScript:function(){for(var t=documentgetElementsByTagName("script"),e=tlength;e--;)if(t[e]getAttribute("cf-hash"))return t[e]}();if(t&&tpreviousSibling){var e,r,n,i,c=tpreviousSibling,a=cgetAttribute("data-cfemail");if(a){for(e="",r=parseInt(asubstr(0,2),16),n=2;alength-n;n+=2)i=parseInt(asubstr(n,2),16)^r,e+=StringfromCharCode(i);e=documentcreateTextNode(e),cparentNodereplaceChild(e,c)}}}catch(u){}}();/ ]]> /</script>,email-b@examplecom<script cf-hash="f9e31" type="text/javascript">
/ <![CDATA[ /!function(){try{var t="currentScript"in documentdocumentcurrentScript:function(){for(var t=documentgetElementsByTagName("script"),e=tlength;e--;)if(t[e]getAttribute("cf-hash"))return t[e]}();if(t&&tpreviousSibling){var e,r,n,i,c=tpreviousSibling,a=cgetAttribute("data-cfemail");if(a){for(e="",r=parseInt(asubstr(0,2),16),n=2;alength-n;n+=2)i=parseInt(asubstr(n,2),16)^r,e+=StringfromCharCode(i);e=documentcreateTextNode(e),cparentNodereplaceChild(e,c)}}}catch(u){}}();/ ]]> /</script>,
git config --local hooksemailprefix '[DI-PR] '
git config --local hooksshowrev "git show -C %s; echo"
git config --local hooksemailmaxlines 100
通过设置一个称为钩子(hook)的东东,来创建这些email通知。jenkins配置:
1,源码管理(Git):
Refspec:+refs/tags/:refs/remotes/origin/tags/
Branch Specifier (blank for 'any'):
2,构建触发器:
Poll
SCM:打勾勾,但是什么都不要填
服务器端部署:
方法有三:
1,git hook
在服务器端部署post-receive hook,内容如下:
[python] view plain copy print
curl [jenkins address]/git/notifyCommiturl=[git clone address]
不需要权限,所以不用加用户名密码,就可以生效了~
2,gerrit hook
如果使用了gerrit的话,git服务器端的hook就不能用了,所以需要找能替代git post-receive的hook,这里可以用ref-updated(注意不是ref-update),内容同上,位置:review_site/hooks
3,gerrit trigger
这里使用的是ref-updated,但是branch哪里不知如何写,试了之后比较乱,分支更新也都触发了,故没有用。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)