Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano and environment variables

I've switched to using environment variables for configuration and it works very well - except when I have to deploy or run tasks with capistrano.

Capistrano 3 seems to execute each command prefixed with /usr/bin/env which erases any environment variables I've set through .bashrc.

EDIT - on doing some more reasearch, this might not be the issue, the issue might be because capistrano executes as a non-login, non-interactive shell and does not load .bashrc or .bash_profile. Still stuck, though.

What would be the best way of making sure the environment vars are set when capistrano executes its tasks?

like image 574
Rahul Sekhar Avatar asked May 15 '14 08:05

Rahul Sekhar


People also ask

Do you need to restart PC after updating environment variables?

No, you don't need to restart your system. However, you have to restart your command prompt application to update the changes done on Environment variables. Save this answer.

What is environment variable in Cypress?

In Cypress, "environment variables" are variables that are accessible via Cypress. env . These are not the same as OS-level environment variables. However, it is possible to set Cypress environment variables from OS-level environment variables.

Does changing system variables require a reboot?

If you set an environment variable with the SET command in a command interpreter, it applies right there and then, to that process' environment. No rebooting, no logging off and on — nothing more required. The environment variables that are held in the registry are not, in fact, environment variables at all.


1 Answers

You might be best looking at the difference between ENVIRONMENT VARIABLES and SHELL VARIABLES

When you fire SSH, your app will load the SHELL variables which are defined in your .bashrc file. These only exist for the life of the shell, and therefore, we don't use them as much as ENV vars

You may be better putting the ENV vars in:

/etc/environment 

Like this:

export ENVIRONMENT_VAR=value 

This will make the variables available throughout the system, not just in different shell sessions


Update

Have you tried

Capistrano: Can I set an environment variable for the whole cap session?

set :default_env, {    'env_var1' => 'value1',   'env_var2' => 'value2' } 
like image 96
Richard Peck Avatar answered Sep 21 '22 13:09

Richard Peck