Teamcity 和 Rake:tc 系统属性在哪里?

发布于 2024-08-02 01:16:40 字数 116 浏览 2 评论 0原文

我正在将一些 NAnt 构建脚本转换为 rake。 有谁知道如何访问我的 rake 脚本中的系统属性(例如 build.number)? Teamcity rake 插件是否会注入它们? 我似乎找不到 doco。

I'm converting some of my NAnt build scripts over to rake. Does anyone know how to access the system properties (e.g. build.number) inside my rake scripts? Is the Teamcity rake plugin even injecting them? I can't seem to find the doco.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁吢 2024-08-09 01:16:40

请参阅预定义属性列表。 在 rake 脚本和 ruby​​ 代码中,这些变量可通过环境获得,例如将其添加到 rakefile 中:

puts 'Build number: ' + ENV['BUILD_NUMBER']

以下代码:

ENV.each {|key, value| puts "#{key} = #{value}" }

如果您想查看所有可用属性,请输入 TeamCity 并检查日志,在所有消息模式下,您将看到可用的属性。

如果您想传递 TeamCity 中可用的或在 agent.conf 文件中定义的其他属性,则应将其添加到 Rake 配置属性和环境变量选项卡中在 Web UI 中。

例如,您想要传递 agent.conf 文件中定义的 system.CUSTOM 属性。 单击添加新变量链接,指定CUSTOM作为名称,指定%system.CUSTOM%作为值。 现在,在rakefile中,您可以将其作为ENV['CUSTOM']访问。

因此,我们的想法是,如果您需要的属性不在已作为环境变量传递的预定义属性列表中,则通过环境传递它们。

Please refer to the list of predefined properties. In the rake script and in the ruby code these variables are available via environment, for example add this in the rakefile:

puts 'Build number: ' + ENV['BUILD_NUMBER']

If you want to see all the available properties, put the following code:

ENV.each {|key, value| puts "#{key} = #{value}" }

Run the build from TeamCity and inspect the log, in the All messages mode you'll see the available properties.

If you want to pass some other property which is available in TeamCity or is defined in the agent.conf file, you should add it in the Properties and environment variables tab of the Rake Configuration in ther Web UI.

For example, you want to pass system.CUSTOM property defined in the agent.conf file. Click the Add new variable link, specify CUSTOM as a name and %system.CUSTOM% as a value. Now in the rakefile you can access it as ENV['CUSTOM'].

So, the idea is to pass the properties you need via environment if they are not in the list of the predefined properties already passed as environment variables.

溇涏 2024-08-09 01:16:40

我想我已经找到了更好的方法来处理这个问题。 如果您安装了 gem java_properties,则将以下代码添加到您的 rakefile 中:

props = JavaProperties::Properties.new(ENV["TEAMCITY_BUILD_PROPERTIES_FILE"])

您现在将拥有一个包含所有系统属性的哈希(减去前导的“system”)。

希望这可以帮助。

标记

I think I've found a better way to handle this. If you install the gem java_properties, then add the following code to your rakefile:

props = JavaProperties::Properties.new(ENV["TEAMCITY_BUILD_PROPERTIES_FILE"])

you will now have a hash that has all of the system properties in it (minus the leading 'system').

Hope this helps.

Mark

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文