提交后,提交后挂钩未运行

时间:2015-02-25 09:11:20

标签: git

我创建了一个简单的提交后脚本:

#!/bin/bash

# Update server when any user commit some changes
# This ssh connection execute a script with sudo that pull git server repo

ssh -i /var/opt/gitlab/.ssh/git_new git@ipaddress "sudo /home/git/pull.sh"
echo "Finished hook execution" >> /tmp/hook_log.txt

脚本位于此路径/var/opt/gitlab/git-data/repositories/systems/repo.git/hooks

暂时有777个permisions。

我正在使用" Source Tree软件"提交我的本地代码到我们的GitLab内部网站。

问题是,当我从shell手动运行该脚本时,一切正常,但在进行提交时却没有 - 推送源树软件。

如果在提交后由git调用post-commit脚本,我如何在日志文件中搜索?

我做错了什么?

提前感谢。

问候。

1 个答案:

答案 0 :(得分:0)

我已经体验过正在运行的钩子进程是在post-receive中:

的/ opt / gitlab /嵌入/服务/ gitlab - 壳/钩

有一个带有ruby代码的模板,我添加了这个:

    #!/opt/gitlab/embedded/bin/ruby
# Fix the PATH so that gitlab-shell can find git-upload-pack and friends.
ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH']

#!/usr/bin/env ruby

# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
# You can add your own hooks to this file, but be careful when updating gitlab-shell!

exec 'echo "pulling from repo" && ssh -i /var/opt/gitlab/.ssh/git_new  git@ipaddress "sudo /home/git/pull.sh"'

changes = ARGF.read
key_id  = ENV['GL_ID']
repo_path = Dir.pwd

require_relative '../lib/gitlab_post_receive'

if GitlabPostReceive.new(repo_path, key_id, changes).exec
  exit 0
else
  exit 1
End

在此之后,从sourcetree,git命令或网站所做的更改将成功执行批处理。

感谢。

问候。