接收后挂钩生成'no such file or directory'错误



我正在尝试为生产网站设置接收后钩子。代码似乎部分有效,但文件未复制。 在这个目录中,我设置了一个裸存储库:

public_html/deploy-dir

在钩子/接收后有以下代码:

#!/usr/bin/env ruby
# post-receive
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
from, to, branch = ARGF.read.split " "
# 2. Only deploy if master branch was pushed
if (branch =~ /master$/) == nil
    puts "Received branch #{branch}, not deploying."
    exit
end
# 3. Copy files to deploy directory
deploy_to_dir = File.expand_path('../')
`GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f master`
puts "DEPLOY: master(#{to}) copied to '#{deploy_to_dir}'"

远程 url 如下所示:

ssh://username@thesite.org/home/username/public_html/deploy-dir

执行"git push production master"时,我在终端中得到以下输出:

Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 300 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: /usr/bin/env: ruby: No such file or directory
To ssh://username@thesite.org/home/username/public_html/deploy-dir
    3a5ab4d..6c49ce0  master -> master

我相信"没有这样的文件或目录"错误与接收后钩子的第 1 行有关。 那里缺少一些东西,我不知道它应该是什么。 此接收后代码在另一台服务器上工作。

或者,我的部署到目录路径可能不正确? 应该是:

deploy_to_dir = File.expand_path('../')

deploy_to_dir = File.expand_path('..')

正如您在注释中指出的,env 的输出表明ruby在远程端的 PATH 中不可用。

你有git,这意味着你有perl。你会考虑以下几点吗?

#!/usr/bin/env perl
# post-receive
use warnings;
use strict;
use Cwd 'abs_path';
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
my($from,$to,$branch) = split " ", scalar <STDIN>;
# 2. Only deploy if master branch was pushed
if ($branch ne "master") {
    warn "Received branch $branch, not deploying.n";
    exit 0;
}
# 3. Copy files to deploy directory
my $deploy_to_dir = abs_path('../');
$ENV{GIT_WORK_TREE} = $deploy_to_dir;
if (system("git checkout -f master") == 0) {
    print "DEPLOY: master($to) copied to '$deploy_to_dir'n";
}
else {
    warn "DEPLOY: checkout failedn";
    exit 1;
}
这是服务器上

没有安装 ruby 的简单问题。 支持已安装的 ruby 并解决问题。

相关内容

最新更新