我正在尝试将一个zip文件打包到我的rake文件中,并且对Rake和ruby缺乏经验,因此我很难确定失败的原因。
这是我尝试过的:
def create_zip_file(targetDirectory, projectToZip)
puts "target:" + targetDirectory
puts "Zipping " + projectToZip
semver_contents = get_contents_of('SEMVER')
zipFileName = 'ProjectName.' + semver_contents
puts zipFileName
files_to_include = "../"+ projectToZip + "/bin/" + BUILD_CONFIG + "/**"
puts "Including the following files: " + files_to_include
Rake::PackageTask.new(zipFileName, semver_contents) do |p|
p.need_zip = true
p.package_files.include(files_to_include)
end
end
我的任务调用如下所示:
exec(:package_zip) {create_zip_file DEPLOY_DIRECTORY, 'ProjectName'}
我这样称呼它:
bundle exec rake package_zip
现在,我从中运行该命令的命令窗口列出了我在脚本中拥有的所有put语句的内容,因此我假设失败是在PackageTask任务内部发生的。
控制台中的错误输出如下所示:
Exec failed, see the build log for more details.
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/albacore-1.0.0/lib/albacore/support/failure.rb:12:in `fail_with_message'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/albacore-1.0.0/lib/albacore/exec.rb:18:in `execute'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/albacore-1.0.0/lib/albacore/support/createtask.rb:24:in `block in exec'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
C:/tools/ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:201:in `block in invoke_prerequisites'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:199:in `each'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:199:in `invoke_prerequisites'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
C:/tools/ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
C:/tools/ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
C:/tools/ruby200/bin/rake:23:in `load'
C:/tools/ruby200/bin/rake:23:in `<main>'
Tasks: TOP => package => package_zip
可能是我错过了一些显而易见的事情或做了一些愚蠢的事情,只是很难抓住它。
在与办公室里的一些人交谈之后,尝试了许多与Pauls答案有关的事情,我终于找到了解决方案,那就是根本不使用打包任务。相反,我们使用rubyzip。
这就是我们最终得到的
def create_zip_file(targetDirectory, projectToZip)
semver_contents = get_contents_of('SEMVER')
zipFileName = "#{targetDirectory}/#{projectToZip}.#{semver_contents}.zip"
filesToZip = FileList["../#{projectToZip}/bin/#{BUILD_CONFIG}/**"]
Zip::File.open(zipFileName, Zip::File::CREATE) do |zipFile|
filesToZip.each do |filename|
zipFile.add(filename, filename)
end
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句