Using capistrano to deploy from different git branches

前端 未结 13 1026
小鲜肉
小鲜肉 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:14

    This solution should work with all versions of Capistrano.

    def branch_name(default_branch)
      branch = ENV.fetch('BRANCH', default_branch)
    
      if branch == '.'
        # current branch
        `git rev-parse --abbrev-ref HEAD`.chomp
      else
        branch
      end
    end
    
    set :branch, branch_name('master')
    

    Usage:

    BRANCH=. cap [staging] deploy
    # => deploy current branch
    
    BRANCH=master cap [staging] deploy
    # => deploy master branch
    
    cap [staging] deploy
    # => deploy default branch
    

提交回复
热议问题