How to pass variable to an Ant build step from a previous batch build step

842 views
Skip to first unread message

Jan Seidel

unread,
Jul 20, 2012, 9:18:23 AM7/20/12
to jenkins...@googlegroups.com
Hi folks,

this is somewhat embarassing for me to ask as I thought I am past that level of expertise but I am facing a pretty basic problem.
I have done research on this issue before addressing it here (of course) but still no joy.

I have a batch build step followed by an Ant build step.
The batch build step defines with some steps and string manipulation a parameter that has to be passed to the Ant script.
Just to mention it, the variable is encapsuled in qoutes due to spaces which else will break the build.

So it looks like
Batch build:
SET param="Went there - didnt like it"

Ant build:
Ant: ant
Target:jar
Build File: TGHU/build.xml
Properties: param

the bold param is just a placeholder in this example
I have tried all kind of formatting like %param%, $param, ${param}, ${ENV,var=param}, ${ENV,var="param"} and still no joy.
The variables are processed in the proerty section. That works also in other jobs but I have obviously never been facing this scenario where the value comes from a preceeding build step and not a build parameter.
In email-ext do we use variables from build steps but still, I don't see the difference.

Do I miss here something or is it for Ant build steps impossible to grab variable from other build steps?

Thanks in advance
Jan

cjo

unread,
Jul 20, 2012, 9:38:18 AM7/20/12
to jenkins...@googlegroups.com
That won't work as the batch script build step runs in a seperate process to the ant build step and therefore enviroment variables are not retained between different build steps.

The solution is to use the envInject plugin [1], and have the batch script output the parameters to a properties file.

e.g.
batch script
echo 'param="Went there - didnt like it"' > env.properties
#append other properties to file as needed


Inject enviroment variables 
set "Properties File Path" to env.properties

then your Ant build step 
where the param shold be avaliable in the same way that the build parameters are.


Chris 

Jan Seidel

unread,
Jul 20, 2012, 11:44:59 AM7/20/12
to jenkins...@googlegroups.com
Ah, ok.
Didn't think about EnvInject.

Thanks :)
Jan
Reply all
Reply to author
Forward
0 new messages