简体   繁体   English

Capistrano 3,使用上传! 在lib / capistrano / tasks中的任务中

[英]Capistrano 3, using upload! in a task in lib/capistrano/tasks

I'm using Capistrano 3 and I want to create my own task. 我正在使用Capistrano 3,我想创建自己的任务。 So I created a file my_new_thing.rake in lib/capistrano/tasks and I can see the task when I run cap -T. 所以我在lib / capistrano / tasks中创建了一个文件my_new_thing.rake,当我运行cap -T时我可以看到任务。 But... some of the methods aren't available. 但是......有些方法不可用。 When I try to use upload! 当我尝试使用上传! I get 我明白了

cap aborted!
NoMethodError: undefined method `upload!' for main:Object

But if I move the same task into config/deploy.rb then then upload! 但是,如果我将相同的任务移动到config / deploy.rb然后上传! method is available. 方法可用。

So what's going on? 发生什么了? How do I create new Capistrano tasks put them in separate file and have them work? 如何创建新的Capistrano任务将它们放在单独的文件中并让它们工作?

I had the same problem, I created my own recipe in a separate file which I loaded in deploy but couldn't get upload! 我有同样的问题,我在一个单独的文件中创建了我自己的食谱,我在部署中加载但无法上传! to work. 上班。

What fixed it for me was adding a role filter inside the task making my final recipe look something like this: 为我修复的是在任务中添加一个角色过滤器,使我的最终配方看起来像这样:

 namespace :figaro do      
   desc "Transfer Figaro's application.yml to shared/config"
   task :upload do
     on roles(:all) do
       upload! "config/application.yml", "#{shared_path}/config/application.yml"
     end
   end
 end
 before "deploy:check", "figaro:upload"

I hope that helps! 我希望有所帮助!

You can create a folder config/recipes for your capistrano recipes if you want to keep them in separate files. 如果要将它们保存在单独的文件中,可以为capistrano配方创建文件夹config/recipes

Use the .rb extension since this isnt a regular rake task. 使用.rb扩展名,因为这不是常规的rake任务。

In config/deploy.rb add this line config/deploy.rb添加此行

load File.expand_path('../recipes/my_new_thing.rb', __FILE__)

If you want to use the rake tasks then you will need to create a task in the deploy file which calls that rake tasks which is not that smart of a move. 如果您想使用rake任务,那么您将需要在部署文件中创建一个任务,该任务调用那些不那么聪明的rake任务。 So as @Sharagoz suggested the best route will be to create your own recipe file and include that in. 因此@Sharagoz建议最好的方法是创建自己的配方文件并将其包括在内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM