FernandoEscher
FernandoEscher

Reputation: 2990

Cannot load configuration for Capistrano Receipe

The thing is that I want to get parameters for my Capistrano recipe from the console, so after looking on Google I came up with this:

task :set_repo do
  set :repository,  "[email protected]:#{configuration[:repo]}/MyApp.git"
  set :scm_user,  configuration[:repo]
end

When trying to run the task, I come up with a "method missing" error for the configuration hash. And after another search on Google I found that I have to load the configuration from Capistrano, so I added this code:

configuration = Capistrano::Configuration.respond_to?(:instance) ?
  Capistrano::Configuration.instance(true) :
  Capistrano.configuration(:must_exist)

But that's throwing a LoadError with the message "Please require this file from within a Capistrano recipe". I have tried requiring the capistrano/configuration module, but I keep getting the same error.

Any help is greatly appreciated.

Upvotes: 2

Views: 901

Answers (2)

choover
choover

Reputation: 852

You can set capistano variables from the command line.

For example, the below invocation would set the capistrano variable scm_user to 'userA' and the capistrano variable repository to "http://myrepo.com/blah":

cap deploy -s scm_user="userA" -s repository="http://myrepo.com/blah"

This has the same effect as putting

set :scm_user, 'userA'
set :repository, 'http://myrepo.com/blah'

at the top of your deploy.rb file.

Upvotes: 0

FernandoEscher
FernandoEscher

Reputation: 2990

Well, I found a work around without using the configuration at all.

It seems that you can set a couple of tasks outside a namespace like this

desc "Use UserA's git repository"
task :usera do
  set :repository,  "[email protected]:UserA/MyApp.git"
  set :scm_user,  "UserA"
end

desc "Use UserB's git repository"
task :userb do
  set :repository,  "[email protected]:UserB/MyApp.git"
  set :scm_user,  "UserB"
end

and after doing this, you can simply call your deploy task prepending your repository task in the console. For example:

$ cap usera deploy

So this is going to call first your usera task and then your deploy task.

Upvotes: 1

Related Questions