5

Is there a way how to fetch a git revision variable from Capistrano 3?

I can't figure out how to access capistrano variables:

namespace :deploy do

  after :finished, :set_current_version do
    on roles(:app) do
      # dump current git version
      within release_path do
        execute :echo, "#{fetch(:revision_log_message)} >> public/version"
      end
    end
  end
end
Tombart
  • 30,520
  • 16
  • 123
  • 136

2 Answers2

8

This one works

  after :finished, :set_current_version do
    on roles(:app) do
      # dump current git version
      within release_path do
        execute :echo, "#{capture("cd #{repo_path} && git rev-parse --short HEAD")} >> public/version"
      end
    end
  end
Tombart
  • 30,520
  • 16
  • 123
  • 136
1

This feature is added in 3.0.1, see their changelog!

Lee Hambley
  • 6,270
  • 5
  • 49
  • 81
  • Thanks, you mean this one? https://github.com/capistrano/capistrano/commit/e61f060426d2c49b1d02b03db84cfe20a0c59aee – Tombart Nov 04 '13 at 13:34
  • Ok thanks, I'm still confused from the new syntax. Is there a way how to list available variables in context? – Tombart Nov 05 '13 at 08:07
  • No, sorry. That is something of a weakness of the `set()` and `fetch()` which is why it's largely removed from the core (a lot of things are real variables now). The Capistrano source code is very simple, and is worth a read. – Lee Hambley Nov 05 '13 at 11:03
  • It's not in 3.0.1, but will be in the next version – Shane O'Grady Jan 09 '14 at 19:26