Tuesday, December 11, 2012

Rake Task with Arguments

The following example shows how to pass an argument to Rake Task. Here version No(:no) gets passed to task and the same gets saved into versions table. This example can be incorporated with your build management script to update the current version No. for each release.

namespace "build" do
 desc "This will update the version No."
 task :version, [:no] => :environment do |t, args|
   raise "Message: Version Number Required to build !!!" if args.no.nil?
   version = Version.first # assume you have a table named versions(:id, :version_no, :updated_at...)
   version.update_attributes(:version_no => args.no)
   puts "Build updated with Version No.#{args.no}"

Usage:  rake "build:version[1.3.2]"

No comments: