Deploy once a specific branch with capistrano?

2019-07-04 05:43发布

问题:

We have a very simple branching strategy:

  • develop -> Development branch
  • staging -> Staging Server Deploy Branch
  • master -> Productio Branch

Our production deploy workflow is develop -> staging -> master. We always deploy first to staging, we test for some time, and then we deploy to production.

Right now we're working in a new feature that I would like to test. I don't want to put it in staging because, since is experimental, I would not like to lock a production deploy until the feature is finished.

Is there a way to say to capistrano the branch I want for one particular deploy, so I could put this experimental code in staging to test it?

OBS: The reason I need to put in staging is that this piece of code depends on a lot of external resources that are already configured in staging and would be difficult to replicate locally.

回答1:

Here's how I do it.

At the top of my config/deploy/staging.rb file, I put this:

set :branch, ENV.fetch("CAPISTRANO_BRANCH", "staging")

This tells Capistrano that when I run cap staging deploy, use the staging branch by default, but allow that to be overridden by the CAPISTRANO_BRANCH environment variable.

So now if I want to deploy a custom branch to staging, it is as simple as this:

CAPISTRANO_BRANCH=my-feature cap staging deploy