Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I instruct Capistrano 3 to load my shell environment variables set at remote host?

I want to instruct Capistrano to load environment variables that are defined on remote server. How can I do that?

It seems that when I export my environment variables inside .bashrc file, they are not taken into account by Capistrano. Capistrano seems to be executing a /usr/bin/env to create the environment for executing remote commands, but this does not seem to be loading the environment variables from .bashrc.

Let me tell you also that I am using rvm-capistrano too (just in case it might help).

Any clue?

like image 356
p.matsinopoulos Avatar asked Aug 25 '14 05:08

p.matsinopoulos


1 Answers

Capistrano actually does load .bashrc. But near the top of the file you will find one of the following lines:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

If you do any exporting after the above lines, it will not be reached by Capistrano. The solution was simply to move my setup above this line—and Capistrano works how I want.

This solution was also noted at this GitHub issue.

like image 195
Delameko Avatar answered Nov 14 '22 09:11

Delameko