Git 提交后钩子未在提交后运行
我创建了一个简单的提交后脚本:Git 提交后钩子未在提交后运行,git,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
#!/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个临时许可证
我使用源代码树软件将我的本地代码推送到我们的GitLab内部网站
问题是,当我从shell手动运行该脚本时,一切都正常,但当我通过源代码树软件执行提交推送时,一切都不正常
如果git在提交后调用提交后脚本,我如何在日志文件中搜索
我做错了什么
提前谢谢
关于。我已经体验到运行的钩子进程是post-receive-in: /opt/gitlab/embedded/service/gitlab shell/hooks 有一个带有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命令或网站所做的更改将成功执行批处理
谢谢
注意。在脚本中添加一些消息,并检查系统日志。gitlab用户是否有权使用ssh登录git@ipaddress没有密码?iPadders上的git用户是否能够在没有密码的情况下调用sudo/home/git/pull.sh?我在syslog中添加了logger,但没有消息,但如果我在控制台中执行它,则可以。如果我注释ssh-i/var/opt/gitlab/.ssh/git\u newgit@ipaddresssudo/home/git/pull.sh也没有在/tmp/hook_log.txt中写入消息。