Peter Clotworthy
Peter Clotworthy

Reputation: 146

Ant inline exec arguments

I have tasks running in Ant, which I'm quite new to, as part of a CI chain of build events. I used a tutorial to create the file for testing/linting/etc a PHP application.

The first important directives in the build.xml are:

 <property name="phpmd"   value="phpmd"/>
 <property name="phpunit" value="phpunit"/>

This works fine as is, assuming that phpmd/phpunit are on the path, and using phpunit as a further example, is run under the following target:

<target name="phpunit" unless="phpunit.done" depends="prepare" description="Run unit tests with PHPUnit">
    <exec executable="${phpunit}" resultproperty="result.phpunit" taskname="phpunit">
        <arg value="--configuration"/>
        <arg path="${basedir}/phpunit.xml"/>
    </exec>
    <property name="phpunit.done" value="true"/>
</target>

All this works well as is- but I want to use docker from now on, which I had hoped would simply mean changing <property name="phpunit" value="phpunit"/> to <property name="phpunit" value="docker-compose run php phpunit"/>, but this instead gives me the following error:

Execute failed: java.io.IOException: Cannot run program "docker-compose run -w /var/www/src php phpunit" (in directory "/var/lib/jenkins/jobs/Blah blah blah/workspace/src"): error=2, No such file or directory

I know that you would usually add additional <arg/> nodes to targets- but is it not possible at all to provide the full command with inline arguments on the initial <property>?

Ant is obviously complaining because, along with those inline arguments, that executable doesn't exist. Will I have to use arg nodes and update every single target?


Using docker-compose alone works fine, but I need the args for the correct container and working directory to be used- preferably inline, otherwise I have to insert many arg nodes.

Upvotes: 0

Views: 410

Answers (1)

Peter Clotworthy
Peter Clotworthy

Reputation: 146

In the end I just created a property for phpunit arguments and then added it by using the <args line="${phpunitArgs}">.

Definitely not ideal, but at least it does what it is supposed to. I certainly prefer using Gulp! XML feels like a bad choice for a build system.

Upvotes: 1

Related Questions