我正在使用Capistrano(3.7.1)将我的Rails 5应用程序部署到VPS。我在git中使用了2个主要分支:master
,用于稳定的生产就绪代码,以及develop
,用于WIP代码。我想将develop
分支部署到临时服务器,但它似乎不起作用。
deploy.rb
:
# This is the failing task
task :check_revision do
on roles(:app) do
unless 'git rev-parse HEAD' == "git rev-parse origin/#{fetch(:branch)}"
puts "WARNING: HEAD is not the same as origin/#{fetch(:branch)}"
puts 'Run `git push` to sync changes.'
exit
end
end
end
production.rb
:
set :branch, 'master'
staging.rb
:
set :branch, 'develop'
每当我尝试部署时,都会失败,如下所示:
$ cap staging deploy
... initial steps, skipped over ...
WARNING: HEAD is not the same as origin/develop
Run `git push` to sync changes.
但事实显然并非如此,正如我所说:
$ git rev-parse HEAD
38e4a194271780246391cf3977352cb7cb13fc86
$ git rev-parse origin/develop
38e4a194271780246391cf3977352cb7cb13fc86
显然是一样的。
发生了什么事?
答案 0 :(得分:2)
你正在用shell编写应该在shell上运行的命令,ruby将其视为String
:
unless 'git rev-parse HEAD' == 'git rev-parse origin/#{fetch(:branch)}'
而不是:
unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}`
你也可以使用:
unless %x{git rev-parse HEAD} == %x{git rev-parse origin/#{fetch(:branch)}}
%x
还返回子shell中运行cmd的标准输出。
答案 1 :(得分:1)
使用反引号在脚本中执行git
命令:
# This is the failing task
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}`
puts "WARNING: HEAD is not the same as origin/#{fetch(:branch)}"
puts 'Run `git push` to sync changes.'
exit
end
end
end