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:
Hi, I’m experiencing this same kind of issue in a project where unit tests are written in jasmine and executed using karma.
First of all I managed to perform these karma unit tests using grunt, and it worked like a charm.
Next step should be to launch “grunt test” from an Ant target within a build.xml file.
I’m writing Ant code for my project using Eclipse IDE, and even if the console keeps telling me “BUILD SUCCESSFULL” I actually have written my karma tests to fail, just like you did and I’m not able to see the karma output that warns me about the fails.
Can you suggest me a way to print the karma output into the Ant/Eclipse console?
LikeLike
This post may help.
StackOverflow – How can I ensure all output from Ant’s exec task goes to stdout?
LikeLike
Yep, I managed to found my solution and already posted it in this very answer
http://stackoverflow.com/a/29703222/4277702
LikeLike
Good to know that you have solved the problem. =)
LikeLike