Using capistrano to deploy from different git branches

前端 未结 13 1048
小鲜肉
小鲜肉 2020-12-22 16:03

I am using capistrano to deploy a RoR application. The codebase is in a git repository, and branching is widely used in development. Capistrano uses deploy.rb f

13条回答
  •  爱一瞬间的悲伤
    2020-12-22 16:25

    Using Capistrano 3.1.0+, none of these were working for me anymore. Instead, according to their commented instructions:

       ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
    

    But, you don't want to use ask or it will prompt you. Instead you should use set. HEAD is the top most branch; 'edge' as it's called. If you want a different branch, replace HEAD with your branch name, eg: master, staging, etc.

    To conclude with examples, in /config/deploy/production.rb, you might include this line:

       set :branch, proc { `git rev-parse --abbrev-ref master`.chomp }
    

    ...or

       set :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
    

    btw, HEAD is the default setting, so no need to really state that in file. Might be used better in a /config/deploy/edge.rb.

    In /config/deploy/staging.rb, you might include this line:

       set :branch, proc { `git rev-parse --abbrev-ref staging`.chomp }
    

    ...or

       set :branch, proc { `git rev-parse --abbrev-ref test`.chomp }
    

    You get the idea!

    I hope these examples help future users of capistrano (^_^)

提交回复
热议问题