S
S
sindrom2010-11-12 17:56:02
PHP
sindrom, 2010-11-12 17:56:02

Specifying an additional argument for ant or phing

Question for everyone who uses ant or phing.
I want to write a script that will deploy some project to a server. At the same time, in the task launch line, I want to be able to specify a variable that will indicate in which environment I am going to deploy (test, production, etc.). I would like it to look something like this:
phing deploy test
Where deploy is the name of the task, of course, and test is a variable pointing to the environment.

My question is how can ant or phing intercept the value of the second argument (after the task name)?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
javax, 2010-11-12
@javax

Can I do separate tasks in the ante? How many deployment types do you have...

M
m00t, 2010-11-12
@m00t

You can pass parameters to phing with -D. Doesn't look very nice - but without crutches IMHO

  <target name="test_env">
    <echo>${environment}</echo>
  </target>

[email protected]:~/***$ phing test_env -Denvironment=test1
Buildfile: ****/build.xml

**** > test_env:

     [echo] test1

BUILD FINISHED

Total time: 0.0969 seconds

L
LastDragon, 2010-11-12
@LastDragon

For ant: (most cut out)

ant [options] [target [target2 [target3] ...]]
Options:
  -D<property>=<value>   use value for given property
  -propertyfile <name>   load all properties from file with -D

ant.apache.org/manual/running.html
But the individual targets are clearer, I think. Another option is to create pseudo-goals whose action will be reduced to setting the desired properties and calling the desired target.
PS When choosing between phing and ant, I stopped at the latter, because. (1) more versatile and (2) fully supported in eclipse.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question