ivoruJavaBoy
ivoruJavaBoy

Reputation: 1357

ANT Reading property from property files, using an ANT property

simple question for you..

I have a property file with a value like this

 CommercialManager=MOT
 CommercialUser=AT
 CommercialAdmin=POT

I'm calling an Ant Script from Jenkins, passing some variables.. some of these variables are used to get a dynamic property from the property file..

I'm saying that if i select into the jenkins job the CommercialAdmin variable from a select list i want to get the property with that name.

The value selected into the Jenkins JOB is set inside a variable ROLE, that is passed to my ANT script..

Below my code:

<property file="Profiles.properties" prefix="profiles"/>

<echo>${profiles.CommercialManager}</echo> 

Doing like this everything works fine, it prints out MOT But as you can see the value is not dynamic, is not the one taken from jenkins job..

So i should do something like this:

<echo>${ROLE}</echo>

But if I do something like this, the print returns the value of the property ROLE that is:

profiles.CommercialManager

and not the value taken from the properties file..

How can i manage this? I think its easy but, its late, and i swimming into a sea of confusion..

Thanks a lot!

Upvotes: 1

Views: 825

Answers (1)

TheEllis
TheEllis

Reputation: 1746

There are a number of ways to dynamically get a property value from a variable described in other threads:

Personally, I would use javascript:

<property file="Profiles.properties" prefix="profiles"/>

<script language="javascript"><![CDATA[
    project.setProperty("CommercialManager", project.getProperty("${Role}"))
]]>
</script>

<echo>${CommercialManager}</echo>

Upvotes: 1

Related Questions