2014-09-10 69 views
1

我正在使用Capistrano v3,我試圖標記部署並將它們推送到github。如何使用Capistrano v3爲Git添加標籤發佈

到目前爲止,我有:

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

我找到了解決方案。

我基本上做了以下內容:

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' 

這使得感十足。我在本地標記部署,而不是直接在服務器上執行:)