Pregunta

I 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
end

And in production, like this:

task :build => :clean do
  compass compile -e production
  jekyll
end
¿Fue útil?

Solución

Yes, you can use environment variables. Here's skeleton implementation:

task :build do |t, args|
  puts "Current env is #{ENV['RAKE_ENV']}"
end

Usage:

% rake build
Current env is 

% RAKE_ENV=development rake build
Current env is development
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top