Teamcity and Rake: Where are the tc system properties?

吃可爱长大的小学妹 提交于 2019-12-06 04:43:00

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/1275056/teamcity-and-rake-where-are-the-tc-system-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!