Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env set :default_env does not work #1872

Closed
kolyadin opened this Issue Mar 29, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@kolyadin
Copy link

commented Mar 29, 2017

Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    airbrussh (1.1.2)
      sshkit (>= 1.6.1, != 1.7.0)
    capistrano (3.7.2)
      airbrussh (>= 1.0.0)
      capistrano-harrow
      i18n
      rake (>= 10.0.0)
      sshkit (>= 1.9.0)
    capistrano-composer (0.0.6)
      capistrano (>= 3.0.0.pre)
    capistrano-file-permissions (1.0.0)
      capistrano (~> 3.0)
    capistrano-harrow (0.5.3)
    capistrano-symfony (1.0.0.rc2)
      capistrano (~> 3.1)
      capistrano-composer (~> 0.0.3)
      capistrano-file-permissions (~> 1.0)
    i18n (0.8.1)
    net-scp (1.2.1)
      net-ssh (>= 2.6.5)
    net-ssh (4.1.0)
    rake (12.0.0)
    sshkit (1.12.0)
      net-scp (>= 1.1.2)
      net-ssh (>= 2.8.0)

PLATFORMS
  ruby

DEPENDENCIES
  capistrano (~> 3.4)
  capistrano-symfony (~> 1.0.0.rc1)

BUNDLED WITH
   1.13.5
set :default_env, { "PATH" => "/opt/php/php-7.1.3/bin:$PATH" }
before 'deploy:started', 'deploy:php_info'

namespace :deploy do

  desc "Checking php version"
  task :php_info do
    on roles(:all) do
      execute "php -v"
    end
  end

end

Printed:

01 php -v
01 PHP 5.5.38 (cli) (built: Dec 10 2016 19:31:59)

Expected
01 php -v
01 PHP 7.1.3 (cli) (built: Mar 18 2017 19:23:29) ( NTS )

echo $PATH

01 echo $PATH
01 /usr/local/bin:/bin:/usr/bin
Expected:

/opt/php/php-7.1.3/bin:/usr/local/bin:/bin:/usr/bin

@mattbrictson

This comment has been minimized.

Copy link
Member

commented Mar 29, 2017

:default_env (as well as many other options) will only be applied if you are passing a symbol to execute. In other words:

# This won't use :default_env
execute "php -v"

# This will use :default_env
execute :php, "-v"

This is covered in the Basic Usage section of the SSHKit README:

Note: In SSHKit, the first parameter of the execute / test / capture methods has a special significance. If the first parameter isn't a Symbol, SSHKit assumes that you want to execute the raw command and the as / within / with methods, SSHKit.config.umask and the comand map have no effect.

Although I sympathize – this is one of the more esoteric aspects of Capistrano. If you have any suggestions on how this can be better documented, let us know or feel free to open a PR!

@kolyadin

This comment has been minimized.

Copy link
Author

commented Mar 29, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.