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

邮差的信 提交于 2019-12-03 06:47:37
Delameko

Although this question is over six months old now, I'll leave this here in case anyone is facing this same problem.

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

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

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

This solution was also noted at this GitHub issue.

Capistrano doesn't load .bashrc since it's not interactive shell. As far as I remember though it does load .bash_profile though so you will probably have better luck using that.

You can pass your current environment variables to a remote execution with ssh by issuing:

env | ssh user@host remote_program

Also taken the example from here

on roles(:app), in: :sequence, wait: 5 do
  within "/opt/sites/example.com" do
    # commands in this block execute in the
    # directory: /opt/sites/example.com
    as :deploy  do
      # commands in this block execute as the "deploy" user.
      with rails_env: :production do
        # commands in this block execute with the environment
        # variable RAILS_ENV=production
        rake   "assets:precompile"
        runner "S3::Sync.notify"
      end
    end
  end
end

looks like you can use with set environment variables for your execution. So read your current environment variables and set them using with .

Jay

In Capistrano 3 it's set :default_env, { ... }

Like here:

set :default_environment, { 
  'env_var1' => 'value1',
  'env_var2' => 'value2'
}

You can refer to this: Previous post..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!