Calling One Rake Task from Another

A quick ruby tip for calling one rake task from another rake task:

namespace :mytasks do

  desc "Task number one"
  task :one do
    # do something here
  end

  desc "Task number two"
  task :two do
    Rake::Task["mytasks:one"].execute
  end

end

Note: Even although task one and task two are within the same namespace, you still have to include the full name (namespace and task name) in the method call.

0 comments