git 配置本地钩子和服务器端钩子

http://www.ituring.com.cn/article/206985

踩过的坑:


      1、服务器端配置钩子的时候记得添加权限

	chmod +x pre-receive 	

pre-receive是你需要授权的文件,当只有-rwxrwxr-x权限的时候,客户端push,服务器端不会调用钩子。pre-receive/update/post-receive分别服务器端钩子,当客户端有commit/push等操作时候会依次调用者三个钩子。


      2、不修改代码,提交空的push也不会调用服务端钩子

      3、服务器端添加钩子拿到提交人信息脚本

zero_commit="0000000000000000000000000000000000000000"
excludeExisting="--not --all"
refnames""
branch=$(git branch | grep "*")
currentBranch=${branch:2}
while read oldrev newrev refname; do 
  # branch or tag get deleted 
  if [ "$newrev" = "$zero_commit" ]; then 
    continue 
  fi 
 
  # Check for new branch or tag 
  if [ "$oldrev" = "$zero_commit" ]; then 
    span=`git rev-list $newrev $excludeExisting` 
  else 
    span=`git rev-list $oldrev..$newrev $excludeExisting` 
  fi 
 
  for COMMIT in $span; 
   do
        AUTHOR_USER=`git log --format=%an -n 1 ${COMMIT}`
        AUTHOR_EMAIL=`git log --format=%ae -n 1 ${COMMIT}`
        COMMIT_USER=`git log --format=%cn -n 1 ${COMMIT}`
        COMMIT_EMAIL=`git log --format=%ce -n 1 ${COMMIT}`

         #cho "AUTHOR_USER>>>"$AUTHOR_USER
         #cho "AUTHOR_EMAIL>>>"$AUTHOR_EMAIL
         #cho "COMMIT_USER>>>"$COMMIT_USER
         #cho "COMMIT_EMAIL>>>"$COMMIT_EMAIL
	 #cho  "COMMIT>>>"$COMMIT_EMAIL
	 #cho  "refname>>>"$refname	
	 refnames=$refname
    done 
done 
echo "origin/"${refnames##*/}

  4、jenkins配置checkStyle思路

      a) gardle中添加checkstyle  task

      b)jenkins添加job 配置该task

      c)在钩子中调用jenkins的checkStyle Job构建





你可能感兴趣的:(其他)