从Rake获取Ruby环境变量(Getting Ruby environment variables from Rake)
我有一个Rakefile,它具有部署或构建应用程序的任务。 这个Rakefile用于生产和开发。
我希望build任务知道环境是什么。 我可以在不运行参数的情况下完成这项工作吗? 它可以通过环境变量来完成吗?
在开发过程中,我需要看起来像这样的任务:
task :build => :clean do compass compile -e development jekyll end在生产中,像这样:
task :build => :clean do compass compile -e production jekyll endI have a Rakefile which has tasks for deploying or building an application. This Rakefile is used in both production and development.
I would like the build task to know what the environment is. Can this be done without passing a parameter to the task when I run it? Can it be done with environment variables?
When in development, I need the task to look like this:
task :build => :clean do compass compile -e development jekyll endAnd in production, like this:
task :build => :clean do compass compile -e production jekyll end最满意答案
是的,你可以使用环境变量。 这是框架实现:
task :build do |t, args| puts "Current env is #{ENV['RAKE_ENV']}" end用法:
% rake build Current env is % RAKE_ENV=development rake build Current env is developmentYes, you can use environment variables. Here's skeleton implementation:
task :build do |t, args| puts "Current env is #{ENV['RAKE_ENV']}" endUsage:
% rake build Current env is % RAKE_ENV=development rake build Current env is development更多推荐
发布评论