从Rake获取Ruby环境变量(Getting Ruby environment variables from Rake)

编程入门 行业动态 更新时间:2024-10-28 06:31:53
从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 end

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

最满意答案

是的,你可以使用环境变量。 这是框架实现:

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 development

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

更多推荐

本文发布于:2023-07-23 04:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1227581.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境变量   Ruby   Rake   environment   variables

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!