Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby GIT post接收多分支部署_Ruby_Git - Fatal编程技术网

Ruby GIT post接收多分支部署

Ruby GIT post接收多分支部署,ruby,git,Ruby,Git,我在同一台服务器上有一个开发和生产文件夹,后面有一个repo,可以根据所推送的分支推送到这两个文件夹。我希望在将develop推送到repo时部署development文件夹,在推送到master时部署production文件夹。我在另一个网站上找到了一个经过编辑的ruby post receive文件,但我是ruby新手,似乎不明白为什么它不推送到任何一个文件夹 #!/usr/bin/env ruby # post-receive from, to, branch = ARGF.read.s

我在同一台服务器上有一个开发和生产文件夹,后面有一个repo,可以根据所推送的分支推送到这两个文件夹。我希望在将develop推送到repo时部署development文件夹,在推送到master时部署production文件夹。我在另一个网站上找到了一个经过编辑的ruby post receive文件,但我是ruby新手,似乎不明白为什么它不推送到任何一个文件夹

#!/usr/bin/env ruby
# post-receive

from, to, branch = ARGF.read.split " "

if (branch =~ /^master/)

    puts "Received branch #{branch}, deploying to production."

    deploy_to_dir = File.expand_path('/var/www/html/production')
    `GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f master`
    puts "DEPLOY: master(#{to}) copied to '#{deploy_to_dir}'"

    exit
    ∂
elsif (branch =~ /^develop/)

    puts "Received branch #{branch}, deploying to development."

    deploy_to_dir = File.expand_path('/var/www/html/development')
    `GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f develop`
    puts "DEPLOY: develop(#{to}) copied to '#{deploy_to_dir}'"

    exit

end

如果你不介意用shell脚本代替Ruby,那么这些人也解决了同样的问题


在这个问题上,参加聚会可能有点晚了,但是它可能会帮助其他试图在Ruby中找到解决方案的人。下面是一个工作示例(修改后的示例使我得到了排序):


我是Ruby新手,所以可能有一种更好的方法来编写这个,但就我所见,它正在按预期工作

第一个
出口下的旋转应该在那里吗?对不起,我对Ruby也不太了解!
#!/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 staging or master branch was pushed
if (branch =~ /staging$/) == nil && (branch =~ /master$/) == nil
    puts "Received branch #{branch}, not deploying."
    exit
end

# 3. Copy files to deploy directory(Path to deploy is relative to the git bare repo: e.g. website-root/repos)
if (branch =~ /staging$/)
    deploy_to_dir = File.expand_path('../path-to-staging-deploy.com')
    `GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f staging`
    puts "DEPLOY: staging(#{to}) copied to '#{deploy_to_dir}'"

elsif (branch =~ /master$/)
    deploy_to_dir = File.expand_path('../path-to-master-deploy.com')
        `GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f master`
        puts "DEPLOY: master(#{to}) copied to '#{deploy_to_dir}'"
else
    puts "Received branch #{branch}, not deploying."
    exit
end