4

Using Capistrano 3.4, is there a command to find the currently deployed version (branch and tag/revision)?

In the deployed root directory there is a file revisions.log. I could create a custom command to parse it, but especially in the case of a rollback, it's not very easy to parse:

Branch master (at 21) deployed as release 20151207160059 by Marco Branch master (at 22) deployed as release 20151207180000 by Marco Marco rolled back to release 20151207160059

marcovtwout
  • 5,230
  • 4
  • 36
  • 45

2 Answers2

3

In the release folder there is a file called REVISION which contains the VCS revision identifier that was deployed. You can simply cat that to get the revision.

will_in_wi
  • 2,623
  • 1
  • 16
  • 21
0

Following on your initial thoughts, get the current revision (via https://stackoverflow.com/a/34156436/2832282) and use the revision.log file to find the matching branch name

revision_string = Rails.root.join('..', '..', 'revisions.log').readlines.detect { |rev| rev.includes?(revision_from_revision_file) }

"Branch production (at 6d68c9415e4d89a6c3119d68a164e50274a2e790) deployed as release 20190301085412 by Cyril"

and then

revision = revision_string.match(
  /^Branch (?<branch>.+) \(at (?<hash>\w+)\) deployed as release (?<release>\w+)/
)
revision['branch'] # => 'production'
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164