如何使用Capistrano v3将版本标记为Git

时间:2014-09-10 19:14:51

标签: git ubuntu github tags capistrano3

我正在使用Capistrano v3,我正在尝试标记部署并将它们推送到github。

到目前为止,我有:

task :tag do 
    on roles (:app) do
      puts "\x1B[35m Tagging deployment... \x1B[0m"

      timestamp = Time.now.strftime("%Y_%m_%d_%H_%M_%S")
      tag_name = "#{fetch(:stage)}_#{timestamp}"
      puts "\x1B[35m tag name... \x1B[0m" + tag_name
      execute "cd #{repo_path} && git tag #{tag_name} && git push origin --tags"

      puts "\x1B[35m Done. Deployment tagged as #{fetch(:tag_name)} \x1B[0m"
    end
  end

事情是repo_path是一个镜像回购,当然我无法执行或使用--tags,因为它会引发错误。

关于如何完成这项非常简单的任务的任何想法?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。

我基本上做了以下事情:

desc "Tag deployed release"
    task :tag do
    run_locally do
      timestamp = Time.now.strftime("%Y_%m_%d_%H_%M_%S")
      tag_name = "#{fetch(:stage)}_#{timestamp}"
      latest_revision = fetch(:current_revision)
      strategy.git "tag -f #{tag_name} #{latest_revision}"
      strategy.git "push -f --tags"
      info "[cap-deploy-tagger] Tagged #{latest_revision} with #{tag_name}"
    end
  end

after :cleanup, 'deploy:tag'

充分理解。我在本地标记部署而不是直接在服务器上进行标记:)