I want to execute a Grunt build in an Ant build project. This could be done by using <exec>.
<?xml version="1.0" encoding="UTF-8"?> <project name="Ant Called Grunt" default="grunt" basedir="."> <target name="grunt"> <exec executable="grunt" dir="${basedir}"> <arg value="build"/> </exec> </target> </project>
It works quite well, but then i realize if there is error in the grunt execution, Ant will still mark the Ant build successful and this may lead to some downstream failure in a continuous integration workflow.
To avoid that, i add a checking on the Grunt output.
<?xml version="1.0" encoding="UTF-8"?> <project name="Ant Called Grunt" default="grunt" basedir="."> <target name="grunt"> <exec executable="grunt" dir="${basedir}" outputproperty="log"> <arg value="kit"/> </exec> <echo message="${log}"/> <condition property="onSuccess"> <matches pattern="Done, without errors." string="${log}"/> </condition> <fail message="Grunt failed!" unless="onSuccess"/> </target> </project>
The idea is to collect the Grunt output in outputproperty and check if the string Done, without errors. exists.
Done =)
Reference:
Filed under: Ant Tagged: Ant, Continuous Integration, Grunt
