Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom variable in capistrano 3

Tags:

capistrano

I was using capistrano 2 with my php project, where I used to define custom variables like this:

set :app_environment, "test"

And then I accessed it in my deploy tasks, e.g.:

run "echo '#{app_environment}' > #{releases_path}/#{release_name}/protected/config/mode.php"

Now in capistrano 3 I define this variable in my stage-specific config files. But I don't have them defined in my tasks:

undefined local variable or method `app_environment' for #<SSHKit::Backend::Netssh:0x007f92323d6988> config/deploy.rb:28:in `block (3 levels) in <top (required)>'

Unfortunately there's not much documentation on the newest version of capistrano and I'm not quite familiar with ruby, so I don't see the way how to do that properly.

like image 675
Anton Sergeyev Avatar asked Nov 06 '13 10:11

Anton Sergeyev


2 Answers

The code should read:

run "echo '#{fetch(:app_environment)}' > #{releases_path}/#{fetch(:release_name)}/protected/config/mode.php"

Although even that is incorrect as run() doesn't exist in Cap3, it's now execute(), so:

execute "echo '#{fetch(:app_environment)}' > #{releases_path}/#{fetch(:release_name)}/protected/config/mode.php"

Beware constructing your command like this nothing will use the command map, or respect the within(), as() or with() constructs.

like image 194
Lee Hambley Avatar answered Oct 20 '22 04:10

Lee Hambley


This is now achieved via 'fetch':

fetch(:app_environment)
like image 41
D1kz Avatar answered Oct 20 '22 04:10

D1kz