views:

37

answers:

1

Hi all, my current code(build.xml) enables me to send email on successful build, but when failed, nothing happens. The targets are called from a build.bat file through command similar to " ........ -DrepositoryAddress=%1 -DbuildResultUUID=%2 startPublish " (for all targets, in order startActivity->startPublish->mailer->startActivity).

Now, I also want email notification when the build fails.I guess trycatch will help me get the task done, but HOW? Not sure about it, where/how to place it(edit it?)? I kind of used trycatch, it gave me something like " Problem: failed to create task or type trycatch" . What modifications are required in current script/xml file to enable this functionality of sending email indicating status of build (successful or failed). Please guide/help.Thanks so much.

'

    <target name="startActivity">
        <fail message="Missing repositoryAddress" unless="repositoryAddress"/>
        <fail message="Missing buildResultUUID" unless="buildResultUUID"/>
        <fail message="Missing activityLabel" unless="activityLabel"/>

    <!-- Replace ADMIN with your real credentials. -->
        <startBuildActivity 
                buildResultUUID="${buildResultUUID}"
                label="${activityLabel}"
                autoComplete="true"
                    repositoryAddress="${repositoryAddress}"
                userId="BuildAdmin"
                    password="Abc1234"/>
</target>

    <target name="startPublish">
    <sleep seconds="10"/>
        <fail message="Missing repositoryAddress" unless="repositoryAddress"/>
        <fail message="Missing buildResultUUID" unless="buildResultUUID"/>

    <artifactfilePublisher repositoryAddress="${repositoryAddress}"
                userId="BuildAdmin"
                   password="Abc1234"
                   buildResultUUID="${buildResultUUID}"
                       filePath="E:\Setup.msi"
                       label="Installer" />

</target>


    <target name="mailer">
     <property name="report" value="E:\Report.html"/>

             <mail from="[email protected]" messagemimetype="text/html" charset="ISO-7779-1" messagefile="${report}" mailhost="HMMMM.company.com" mailport="25" tolist="[email protected]" subject="Build status" />

</target>

    <taskdef name="startBuildActivity"
             classname="com.ibm.team.build.ant.task.StartBuildActivityTask" />
    <taskdef name="artifactfilePublisher"
             classname="com.ibm.team.build.ant.task.ArtifactFilePublisherTask" />


</project>'
A: 

you can implement a BuildListener that sends the email as described in the ant FAQ

Nikolaus Gradwohl
My application is in .NET, is it independent of it? Also, can you still guide me doing the same using some sort of Try/Catch thing in the given build.xml? Thanks.
the build listener the faq describes would not be part of your app but a class ant uses - and ant is written in java. I don't think there is a way to execute a task if the build failes, becaus ant stopps processing the build file if that happens
Nikolaus Gradwohl
hmm, I'll try, but that's what Try/catch is for? if it fails, the code within catch executes.. it's just that I am not sure, how/where to get it done within this script/xml file? Any pointers? Thanks. p.s. I've been recommended to use Try/catch, that's why emphasizing on that technique.
the try/catch block in the BuildListener example of the faq catches errors that happen while sending the mail - not while executing your build. to use it compile the class using javac and make sure it is in ant's classpath, how to activate it is shown just below the code example
Nikolaus Gradwohl