在 Windows 服务器上托管的 TeamCity 上设置 Rails 项目

问题描述:

我正在 Team City 上设置我的第一个 Ruby 项目,该项目托管在 Windows Server 上,但遇到了问题.现在,因为服务器可能没有安装所需的 gems,我添加了一个命令行构建步骤:

I'm setting up my first Ruby project on Team City, which is hosted on a Windows Server, but I'm having a problem. Now, because the server may not have the required gems installed, I've added a command line build step:

bundle install

现在我认为这已经足够了,但显然 bundle 不被识别为内部或外部命令.除了,如果我 RDP 进入服务器,如果我从任何地方运行 bundle install ,那很好,只是通知我没有找到 gemfile.

Now I thought this would be enough, but apparently bundle is not recognized as an internal or external command. Except, if I RDP into the server, if I run bundle install from anywhere, it is fine, and just notifies me that no gemfile was found.

任何关于我是否错过了一步的想法,或者我是否以错误的方式处理这个问题?

Any ideas on if I've missed a step, or I'm going about this the wrong way?

这很可能是 TeamCity 没有找到 ruby​​ 可执行文件的路径的问题.

Most likely this is a problem with TeamCity not finding the path to ruby executables.

您可以通过在构建参数部分覆盖构建配置中 PATH 环境变量的值来解决此问题.

You can address this by overriding the value to the PATH environment variable in your build configuration in the Build Parameters section.

env.PATH=/path/to/ruby;%env.PATH%

有关文档等的正确链接,请参阅此答案.

See this answer for the proper links to documentation, etc.

编辑 #1

我注意到在更新我的一项配置时,TeamCity 应该负责附加值,因此您不需要需要将路径设置为等于自身.上面提到的帖子是 TeamCity 覆盖值的错误的解决方法,但已更正.有关详细信息,请参阅鼠标悬停处的帮助:

I noticed when updating one of my configurations that TeamCity is supposed to take care of appending values so you DO NOT need to set path equal to itself. The post mentioned above is a workaround for a bug where TeamCity was overwriting the values, but that has been corrected. See the help at the mouse-over for more information:

编辑 #2

我测试了编辑 #1,发现情况并非如此.你确实需要

I tested edit #1 and found that is not the case. You do need to

  • 创建环境变量env.Path
  • 并将其值设置为自身加上您的新路径;在我的例子中,C:\Program Files\MySQL\MySQL Server 5.6\bin\;%env.Path%
  • 不需要需要说env.Path=...如上所列;这就是配置文件的样子.
  • create an environment variable env.Path
  • and set it's value to itself plus your new path; in my example, C:\Program Files\MySQL\MySQL Server 5.6\bin\;%env.Path%
  • you do NOT need to say env.Path=... as listed above; that is what the configuration file will look like.

我通过执行以下操作对此进行了测试:

I tested this out by doing the following:

  1. 创建了一个没有仓库的新项目
  2. 向`echo %env.Path% 添加了命令行构建步骤
  3. 添加了调用MySql的命令步骤mysql --help 如果找不到MySql会失败

然后我针对 env.Path 变量的以下每个设置运行它:

I then ran it for each of the following settings for the env.Path variable:

  1. 未添加/更改;TeamCity 按原样报告构建代理的环境变量.
  2. 添加为 C:\Program Files\MySQL\MySQL Server 5.6\bin\.TeamCity 仅报告该条目.
  3. 添加为 C:\Program Files\MySQL\MySQL Server 5.6\bin\;%env.Path%.TeamCity 将 C:\Program Files\MySQL\MySQL Server 5.6\bin\ 添加到 #1 中显示的构建代理值.结果就是我们想要的,#1 + #2
  1. Not added / changed; TeamCity reports out the environment variable for the build agent as is.
  2. Added as just C:\Program Files\MySQL\MySQL Server 5.6\bin\. TeamCity reports out only that entry.
  3. Added as C:\Program Files\MySQL\MySQL Server 5.6\bin\;%env.Path%. TeamCity prepends C:\Program Files\MySQL\MySQL Server 5.6\bin\ to the build agent's values shown in #1. The result is what we want, #1 + #2