2017-05-02 54 views
0

我有同樣的服務器上的開發和生產的文件夾,並在他們身後1個回購推向取決於推分支這兩個文件夾。我想開發文件夾被部署在發展推到回購,當主推生產的文件夾。我有一個編輯紅寶石後收到的文件我在不同的網站上發現,但我是新來的Ruby和似乎無法找出它爲什麼不推到任何文件夾。GIT後收到多個分支部署

#!/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 

任何幫助這個post-receive或更換將不勝感激。

+0

是第一個根據該swiggle'exit'應該在那裏?對不起,對Ruby也不太瞭解! –

回答

0

也許有點晚對這個黨,但也許這將幫助其他人正在努力尋找在Ruby中的解決方案。這裏是(這讓我排序從this source修改)工作的例子:

#!/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 

我是新來的Ruby所以有可能是一個更好的方式來寫這篇文章,但它是按預期工作 - 據我可以看到。