It's all about the answers!

Ask a question

Retrieving BuildDef properties in ANT using RTC Build Agent


Steve White (4021213) | asked Aug 05 '14, 1:08 p.m.
edited Aug 05 '14, 1:10 p.m.
Currently to retrieve the value of a property defined in the BuildDef  I have to prefix it with env in my build.xml file
I.E.
 ${env.userId}

Is there a way to get the values without using the "env" prefix. What I really want is to be able to use the same property name as defined in the Builddef without have to use a prefix. In our product we have ant tasks  already defined and in use for our customer base. What I want to do is to be able to drive it using the RTC Build & BuildDef, but I need to be able to retrieve the properties by the same names.
IS there some way to configure the build agent not to use env as a prefix on properties?
-Steve

Comments
sam detweiler commented Aug 05 '14, 2:59 p.m.

in the build definition, ant tab, last field,  tell it to write all the properties to a file..
(I use filename 'all.properties')

then load that file in your build.xml

here is how i do that in my build file

    <target name="load-props" if="./all.properties">
        <loadproperties srcFile="./all.properties"/>
    </target>


Steve White commented Aug 05 '14, 3:36 p.m.

Thanks, but I am using the cmd line Rational Build agent whihc does not include the ANT tab like the ANT JBE. There is not feature to write properties to a file that I can find.
The reason I have to prefix with "env" is becuase the build.xml uses
 <property environment="env"/> to access the environment variables, which the Builddef & engine properties are set. I'm looking for a way to access these properties without using a prefix.

One answer



permanent link
Nick Edgar (6.5k711) | answered Aug 06 '14, 1:11 p.m.
JAZZ DEVELOPER
edited Aug 06 '14, 1:15 p.m.
You can use -D arguments in the Ant invocation then. e.g. ant build.xml -DbuildResultUUID=$buildResultUUID
where the value uses whatever syntax is necessary in the BF step to substitute the property value.
I'm not sure if BF has some way of exporting all the properties in .properties file format.  If so, you could do as Sam suggests, or use -propertyfile. See https://ant.apache.org/manual/running.html


Comments
Nick Edgar commented Aug 06 '14, 1:14 p.m. | edited Aug 06 '14, 1:15 p.m.
JAZZ DEVELOPER

Or the mapping could be done in the Ant script itself, e.g.

<property name="buildResultUUID" value="${env.buildResultUUID}"/>

You could also try:
<property environment=""/>
to try importing all env vars without a prefix, but I've not tried that myself.


Steve White commented Aug 06 '14, 2:11 p.m.

Nick, thanks for the feedback and suggestion. Currently I do:
ant -f ${zbuildPath}/zBuildAntRBA.xml -lib ${zbuildPath} -lib ${buildSystemPath}/buildtoolkit
defined as the BuildDef command parm. We have many properties for a specific build type though 20+, so it becomes tedious and a service complication, which we are trying to avoid having to do. It would be nice if the BFA had a way to write to a properties file like the JBE. That would really help and keep things simple.
-Steve


Steve White commented Aug 08 '14, 10:30 a.m.

Nick, I'm also attempting to integrate Jenkins with our Build tool. I'm following the scenario https://jazz.net/wiki/bin/view/Main/JazzScmWithJenkins which appears you were involved.
My question is, Are properties defined in the RTC BuildDef passed to the ANT task that is defined in the Jenkins Project Build Invoke Ant or must all properties be defined in Jenkins Build Invoke Ant properties section?
-Steve


sam detweiler commented Aug 08 '14, 10:56 a.m.

properties in the build job and build def are not passed all the way thru to the ant job (as env variables)..

this is why I use the ant properties file (on the ant tab of the build definition) and load them in my ant task.  (see comment 1 to original question)


Steve White commented Aug 08 '14, 3:38 p.m.

There is no Ant tab or field to write props to a file via the RTC BuildDef for Jenkins, so that solution is not possible. It seems to me that properties defined in the RTC BuildDef would be passed to Jenkins in some form, but apparently they are not. I tested this and indeed the properties are not available in the Jenkins Build Ant script. Seems to me if RTC is integrated to work with Jenkins that properties defined in the RTC BuildDef would be passed; otherwise why have the propeties tab in the RTC BuildDef for Jenkins.


Steve White commented Aug 08 '14, 3:50 p.m.

I was able to pass RTC BuildDef properties into the Jenkins Ant task by also defining the property as a Build parameter in the Jenkins Project. This is a duplication of effort and a serviceability concern to have to keep both in sync.


Steve White commented Aug 08 '14, 5:02 p.m.

What I found is when I submit the build for RTC it modifies the Jenkins project to be a Parametrized build and adds the buildResultUUID as a parm. Even if I delete that parm it readds it on the next RTC Build request. It doesn't add it if I build form Jenkins. Therefore I have to ask why doesn't the RTC Jenkins integration do that for all the properties defined in the RTC BuildDef and Build Engine? That would allow the user to only have to define properties in RTC.


Nick Edgar commented Aug 11 '14, 11:34 a.m.
JAZZ DEVELOPER

We are fairly limited here by the Jenkins REST API. AFAICT, there's no way to pass a set of properties in one go, as a properties file, so they need to all be defined as parameters.  When we added buildResultUUID (needed for sync to RTC build result) it was unclear that we should sync all properties, e.g. if using Jenkins plugin or JBE to run the SCM phase of the build, it pulls the SCM config properties from the build request.

It's a reasonable to request to offer to sync all properties though. Feel free to file an enhancement request for that.

showing 5 of 8 show 3 more comments

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.