Dane O'Connor
Dane O'Connor

Reputation: 77358

Teamcity and Rake: Where are the tc system properties?

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.

Upvotes: 4

Views: 1752

Answers (2)

Mark
Mark

Reputation: 588

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

Upvotes: 2

CrazyCoder
CrazyCoder

Reputation: 402413

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.

Upvotes: 6

Related Questions