I would like to be able to send mail (for example) whenever the Ant build process fails.
how can I do it in Ant environment?
The problem is that, as far as I understand the Tasks flow in Ant- whenever a task fails in a given list of tasks in Ant process, it throws an exception that causes the process to exit without continueing to the next tasks. So I need a tool to catch such exception and handle this error flow.
Didn't find so far documented solution to my problem.
There's a concept called a logger that can send an e-mail with the results. That would send it out either way. For only failure, you could implement your own listener. Or you could just do it in the operating shell script that calls Ant for you.
OK, the logger concept is indeed already a prgoress in the right direction.
I am now having troubles in configuring the content of this email.
I'd like the mail to contain the tail of the last 10-20 lines of the log file that was created during the build
so it will include the last error that caused the build to fail.
doesn't supply a property to handle the Mail's body. They mention there the to, from, subject but not the body and therefore
I got empty email.
I also tried to add to the process ant ... - logger ... -logfile ... but it still didn't change anything in result mail of the build process.
Joined: Aug 09, 2009
I'll try to be clearer:
I am using the command line:
acm.nightly is our specific build task
and in addition defined the mandatory property for the use of the maillogger:
The resut in case of build failure:
I get a mail from the MailLogger but its body is empty even though the file log/build.log is not empty. while I thought that by default it should contain the content of log file (or better on the last 20 line of it).
I'll be glad to get any suggestion what I should do.
Guy Roth wrote:So, anyone know how I can get a mail with the build log errors in case the build failed using Ant?
Not me. But I'd suggest to take a look at a continuous integration server such as Cruise Control or Hudson.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
There are various ways of doing this. As others have already pointed out, this can be done outside Ant. But if you want it to be part of Ant, then you could you either of these 2 ways:
1) Use the Log4jListener http://ant.apache.org/manual/listeners.html#Log4jListener which will log the task message to a log file. To trigger a mail, you can configure a log4j category and a SMTPAppender in the log4j.xml for the build finished event (org.apache.tools.ant.Project event). Just an example (will need tweaking, because the org.apache.tools.ant.Project event will be triggered both at start and stop of the builds).
Guy Roth wrote:Does anyone know to tell me how to configure Ant to send email with the build errors in case the build failed?
We're back to the original suggestions - write your own logger or write an operating system script. Why don't you pick one and ask when you have more concrete suggestions on the approach?
Joined: Aug 09, 2009
About the last responses:
1. First of all I don't think that I need to extend the 'org.apache.tools.ant.listener.MailLogger' ready made logger. I don't have any requirements different than the statdard.
I just don't understand why when I tried to use this logger it sent mail with empty body although it was suppose to append to an inner buffer every line that is logged and then send it as the body of the mail when the 'buildFinished' event is thrown. There must be something that I wrote wrong that causes this problem and therefore I asked in this forum how others do use the ordinery MailLogger
2. Since I saw I am not progressing, I followed the recommendation that was given here and extended the MailLogger by writing logger that inherit it in Java. But when I tried to use it in the command line:
If you need any other options, I looked it up from the command line page. (I forgot if it was -cp, -lib or -build.) The downside to writing reusable code is you only see it once .
Joined: Aug 09, 2009
OK, seems like the problem is solved, also thanks to the advices here.
What seems to be the problem was that I am using Ant 1.6.2 and perhaps the MailLogger in this version doesn't work properly.
I found the source file of MailLogger of version 1.7 and added this class as an extension to my project and then the MailLogger return to work properly including sending the content of the log file as the body of the mail.