John Small
John Small

Reputation: 981

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

I'm using Capistrano 3 and I want to create my own task. So I created a file my_new_thing.rake in lib/capistrano/tasks and I can see the task when I run 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! method is available.

So what's going on? How do I create new Capistrano tasks put them in separate file and have them work?

Upvotes: 4

Views: 3666

Answers (3)

David Svensson
David Svensson

Reputation: 568

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!

Upvotes: 16

Arctodus
Arctodus

Reputation: 5847

You can create a folder config/recipes for your capistrano recipes if you want to keep them in separate files.

Use the .rb extension since this isnt a regular rake task.

In config/deploy.rb add this line

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

Upvotes: 1

Qaiser Wali
Qaiser Wali

Reputation: 358

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. So as @Sharagoz suggested the best route will be to create your own recipe file and include that in.

Upvotes: 0

Related Questions