我试图将我们的capistrano2脚本升级到最新的capistrano,然而却努力让它工作。为了限制转换的任何问题,我开始了一个空项目,并做了cap install
。
添加了自定义任务以在计算机上本地运行并尝试了它。结果相同。
这是我得到的错误:Errno::ENOENT: No such file or directory - /usr/bin/env dir
确切说明:
1)mkdir capdemo
2)cd capdemo
3)上限安装
4)使用以下内容在lib / capistrano / tasks / foo.rake下创建文件:
namespace :foo do
desc "Foo"
task :local do
run_locally do
execute :dir
end
end
end
5)运行cap staging foo:local
我正在运行Windows 10,ruby 2.2.4和capistrano 3.8.1
```mr@MR-LAPTOP MINGW64 ~/inpay_git/capdemo
$ cap staging foo:local -p --trace
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke foo:local (first_time)
** Execute foo:local
Config variable set: :print_config_variables => true
Config variable set: :stage => :staging
Config variable set: :scm => :"default-git"
Config variable set: :branch => "master"
Config variable set: :deploy_to => #<Proc:0x376d6a0@C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/defaults.rb:25 (lambda)>
Config variable set: :tmp_dir => "/tmp"
Config variable set: :default_env => {}
Config variable set: :keep_releases => 5
Config variable set: :format => :airbrussh
Config variable set: :log_level => :debug
Config variable set: :pty => false
Config variable set: :local_user => #<Proc:0x33c43f8@C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/defaults.rb:36 (lambda)>
Config variable set: :format => :airbrussh
Config variable set: :git_shallow_clone => false
Config variable set: :git_wrapper_path => #<Proc:0x3776310@C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/scm/git.rb:9 (lambda)>
Config variable set: :git_environmental_variables => #<Proc:0x3775d10@C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/scm/git.rb:15 (lambda)>
Config variable set: :application => "my_app_name"
Config variable set: :repo_url => "git@example.com:me/my_repo.git"
Config variable set: :scm => :git
00:00 foo:local
01 dir
cap aborted!
Errno::ENOENT: No such file or directory - /usr/bin/env dir
C:/Ruby/224/lib/ruby/2.2.0/open3.rb:193:in `spawn'
C:/Ruby/224/lib/ruby/2.2.0/open3.rb:193:in `popen_run'
C:/Ruby/224/lib/ruby/2.2.0/open3.rb:93:in `popen3'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/local.rb:44:in `execute_command'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:141:in `tap'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:74:in `execute'
C:/Users/mr/inpay_git/capdemo/lib/capistrano/tasks/foo.rake:5:in `block (3 levels) in <top (required)>'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:29:in `run'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/dsl.rb:70:in `run_locally'
C:/Users/mr/inpay_git/capdemo/lib/capistrano/tasks/foo.rake:4:in `block (2 levels) in <top (required)>'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `call'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/airbrussh-1.2.0/lib/airbrussh/rake/context.rb:62:in `execute'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
C:/Ruby/224/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/lib/capistrano/application.rb:14:in `run'
C:/Ruby/224/lib/ruby/gems/2.2.0/gems/capistrano-3.8.1/bin/cap:3:in `<top (required)>'
C:/Ruby/224/bin/cap:22:in `load'
C:/Ruby/224/bin/cap:22:in `<main>'
Tasks: TOP => foo:local```
答案 0 :(得分:0)
默认情况下,使用Capistrano执行的命令以/usr/bin/env
为前缀。如果系统上没有/usr/bin/env
,则命令将失败。我不熟悉Windows,所以我不知道这是否是一个不可逾越的问题。
如果要删除/usr/bin/env
前缀,可以修改Capistrano&#34; s&#34;命令映射&#34;删除所有默认行为:
# In deploy.rb
# NOT RECOMMENDED
SSHKit.config.command_map = SSHKit::CommandMap.new({})
但这会影响本地和远程命令,这是不可取的。同样,Capistrano假设您希望在本地和远程环境中以相同的方式运行。
如果这些限制和变通方法过于严格,则您不必使用run_locally
。事实上,无论如何,run_locally
并未得到卡皮斯特拉诺的很好支持,而维护者(包括我自己)discourage using it。相反,您可以使用Ruby的内置方法来运行本地命令,例如system
或反向标记。