• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I handle Build Failure in Ant?

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



10x ahead
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guy,
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.
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

the Document about the logger
http://ant.apache.org/manual/listeners.html

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.
Any suggestions?
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone?

I'll try to be clearer:
I am using the command line:


where:
acm.nightly is our specific build task

and in addition defined the mandatory property for the use of the maillogger:
MailLogger.mailhost=
MailLogger.from=
MailLogger.failure.to=

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.

 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guy,
I don't know. I use a UNIX script to send mail. (After doing some filtering to get relevant lines.) I had heard of the logger so shared, but that's as far as my experience with it goes.
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,
1. what is the content of the mail that is sent from Ant - doest it contain the build log file?
2. can you provide the script that runs the Ant build task?
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, anyone know how I can get a mail with the build log errors in case the build failed using Ant?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).



2) Or you could implement your own listener (which would probably extend the MailLogger http://ant.apache.org/manual/listeners.html#MailLogger) to even send the logs as the email body.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guy Roth wrote:Jeanne,
1. what is the content of the mail that is sent from Ant - doest it contain the build log file?


It contains pieces of the build log file.

Guy Roth wrote:2. can you provide the script that runs the Ant build task?


No. It's the intellectual property of my employer. I can tell you that it's basically a bunch of find/grep statements that look for strings of interest to us.
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know to tell me how to configure Ant to send email with the build errors in case the build failed?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

I got java.lang.ClassNotFoundException so my question is how can I provide a class path to ant command line?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guy Roth wrote:I got java.lang.ClassNotFoundException so my question is how can I provide a class path to ant command line?


-lib <path>

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 .
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

So great, I can close this issue!

 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guy Roth wrote:So great, I can close this issue!


Great! I've been on Ant 1.7 for over a year and forgot about the old one .
 
reply
    Bookmark Topic Watch Topic
  • New Topic