Retrieving BuildDef properties in ANT using RTC Build Agent
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 |
One answer
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 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:
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.
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)..
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.
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
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.
Comments
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>
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.