user1221490
user1221490

Reputation: 1

How to get error code of ant command

My ant files are already present and I am not allowed to change those for various reasons.
I have created a batch file and I am writing all those ant commands in that batch file just to automate the process.
The code looks something like this

1.  cd abc
2.  ant realclean && ant
3.  cd..
4.  cd pqr
5.  ant realclean && ant
6.  cd..

However now I have to check if the build fired on line 2 is successful then only goto line 3 otherwise exit.

I googled a bit and found %errorlevel% as one option but it is not working in my case.

Any suggestions?

Thanks in advance.

Upvotes: 0

Views: 937

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328754

How about adding another ANT file which contains the tasks to execute the existing ANT files?

That would give you error handling without doing anything, you could reuse that file on different OSs and your CI server and the syntax would be saner than batch...

You can have ANT execute, say project.xml, with ant -f project.xml

[EDIT] You don't even have to change the existing projects: Just create a new project, assign paths to the old projects to properties in the new build.xml and then you can build the old projects from the new one.

This gives you:

  • A sane[*] syntax that you already know (no need to learn the ugly/buggy/handicapped rules of DOS batch programming; you did know that DOS was once named QDOS "Quick and Dirty OS", yes?)
  • Proper error handling
  • A simple way to pass arguments to the sub-builds
  • Cross-platform support
  • Useful error messages when something goes wrong

[*]: Compared to DOS...

Upvotes: 1

Related Questions