Question

I don't understand task ordering in capistrano. (Using 3.2 version)

UPDATED example of code

test_ordering.cap file contains:

namespace :test_ordering do

  desc 'Starting task'
  task :start_testing do
    puts 'This task must be in the middle'
  end

  desc 'First message'
  task :first_message do
    puts 'This task must fire first, before starting task'
  end

  desc 'Second message'
  task :second_message do
    puts 'This task must be the last'
  end

  before 'test_ordering:start_testing', 'test_ordering:first_message'
  after 'test_ordering:start_testing', 'test_ordering:second_message'
end

When I'm doing bundle exec cap staging test_ordering:start_testing it returns:

ruby 2.0.0p451 (2014-02-24 revision 45167) [i686-linux]
This task must be in the middle
This task must fire first, before starting task
This task must be the last

Why does 'before' fires after the 'prepare' task? My environment uses Ruby 2.0.0p451, Rails 4.0.4, and Capistrano 3.2.

Was it helpful?

Solution

Works for me:

Matt-Gibsons-iMac:captest matt$ cap -V
Capistrano Version: 3.2.1 (Rake Version: 10.1.0)
Matt-Gibsons-iMac:captest matt$ cap staging test_ordering:start_testing
This task must fire first, before starting task
This task must be in the middle
This task must be the last

All I did was cap init, paste your code into /lib/capistrano/tasks/test_ordering.rake, and run.

You say you're using a .cap file -- the latest Capistrano prefers .rake files, so combined with my correct result would make me think that you might be running across a bug in an old version of Capistrano.

Looking at the recent issues history, I'm guessing it's this bug, fixed in 3.2.1 that you're hitting. Upgrade to 3.2.1 and your problem should disappear.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top