【问题标题】:Echo in capistrano task make empty fileCapistrano 任务中的 Echo 生成空文件
【发布时间】:2015-10-08 20:45:50
【问题描述】:

我尝试在部署时创建具有完整提交哈希的 REVISION 文件。

#early..
revision = %x[git rev-parse HEAD]
set :revision, revision

namespace :assets do
    task :install do
        on roles :all do
            puts fetch(:revision, "")   #it's good, print ee51dc1308a07cb0dfadd60b2a9d1b3485614034

            execute :sh, "-c 'echo #{fetch(:revision, "")} > #{release_path}/REVISION2'" 

            execute :sh, "-c 'cat #{release_path}/REVISION2'" #empty output

            execute :php, "#{release_path}/public/index.php assetic build"
        end
    end
end 

因此,我的文件 REVISION2 没有内容。

Capistrano 版本:3.4.0(Rake 版本:10.1.0) 开发机器:Ubuntu 14.04.2 LTS 部署到 CentOS 6.4 版(最终版)

【问题讨论】:

    标签: capistrano capistrano3


    【解决方案1】:

    我通过在本地写REVISION文件来解决这个问题,然后用下面的任务上传

    task :save_revision do
        revision = %x[git rev-parse HEAD]
    
        File.open("REVISION", 'w') { |file| file.write(revision) }
    
        set :revision, revision  #save for future
        puts revision #print
    
        on roles :all do
           upload! "REVISION", "#{release_path}"
        end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-18
      • 2011-03-24
      • 1970-01-01
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-07
      相关资源
      最近更新 更多