简体   繁体   English

从Rails Shell命令运行捆绑软件

[英]Running bundle from rails shell command

I have a Rails 4 application that executes several shell commands and everything works fine, but now I am trying to execute a shell command from it that checks the bundle of a different app or even an engine not used by this app, and all I get is the result as if it was checking its own bundle. 我有一个执行几个shell命令的Rails 4应用程序,并且一切正常,但是现在我试图从中执行一个shell命令,该命令检查另一个应用程序或该应用程序未使用的引擎的捆绑包,我得到的一切结果就像检查自己的包一样。

This is probably confusing so let me try to make it clearer: 这可能令人困惑,所以让我尝试使其更清晰:

Rails app
  |--operations folder
      |--app1
      |--engine1
      |--app2

now the rails app executes a shell command to check the bundle of any of those apps/engines in the operations folder like this: 现在,rails应用程序执行一个shell命令,以检查Operations文件夹中所有这些应用程序/引擎的捆绑包,如下所示:

out = %x[cd operations/app1 && bundle list 2>&1]

but the result is the list of gems used by the executing Rails app, not the list of gems from app1 that i want to check. 但是结果是正在执行的Rails应用程序使用的宝石列表,而不是我要检查的app1中的宝石列表。

Why is that happening? 为什么会这样呢? I've also tried specifying the Gemfile using the --gemfile= option to no avail. 我也尝试使用--gemfile=选项指定Gemfile,但无济于事。 how can I execute bundle operations on the target app? 如何在目标应用程序上执行捆绑操作?

The reason for this is that I have built a continuous integration application that tests and builds packages from our other apps and engines and sometimes some of the apps/engines require gems that the CI doesn't have, so running their tests fails and I wanted to make the CI install them before running the tests if it doesn't have them. 原因是我建立了一个持续集成应用程序,该程序可以从其他应用程序和引擎测试并生成软件包,有时某些应用程序/引擎需要CI没有的gem,因此运行其测试失败了,我想如果没有测试,则让CI在运行测试之前先安装它们。

By default, child processes inherit the environment set up by Bundler. 默认情况下,子进程继承Bundler设置的环境。

To suppress this behaviour, call Bundler.with_clean_env with a block that contains the commands you want to run in the clean environment: 要抑制此行为,请使用包含要在干净环境中运行的命令的块调用Bundler.with_clean_env

out = Bundler.with_clean_env { %x[cd operations/app1 && bundle list 2>&1] }

For more on this, see http://bundler.io/man/bundle-exec.1.html#Shelling-out 有关更多信息,请参见http://bundler.io/man/bundle-exec.1.html#Shelling-out

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM