Nant “nant.onsuccess” property

nant

I have a nant file which does the building of my project. Once the build succeeded, I will use the nant.onsuccess property to send mail. In this nant.onsuccess I will call next batch of targets to build. But I need to send the mail depending on the success or failure of these set of targets that are called from the nant.onsuccess target.

eg:

     <?xml version="1.0" encoding="utf-8" ?> 
     <project name="Build.build" default="default">
     <property name="mail.mailhost" value="x"/>
     <property name="mail.from" value="y"/>
     <property name="mail.to" value="z"/>
     <target name="default" description="Just like that">
      <echo message="Succeeded"/>
      <echo message="Succeeded"/>
      <property name="nant.onsuccess" value="suc"/>
     </target>

     <target name="suc" description="Just like that">
       <echo message="I am called"/>
       <echo message="in success part"/>
       <property name="nant.onsuccess" value="here"/>
       <call target="testing"/>
     </target>
     <target name="testing">
       <echo message="I ammmmmmmmmm"/>
       <property name="nant.onsuccess" value="here"/>
     </target>
     <target name="here">
     <echo message="I should not be called"/>
     </target>


   <target name="nant.onfailure">
  <if test="${string::get-length(mail.to) > 0}">
  <mail mailhost="${mail.mailhost}" from="${mail.from}" tolist="${mail.to}"
    subject="Test mail on ${environment::get-variable('COMPUTERNAME')}.">
    Note: this is ignored.
   </mail>
   </if>
  </target>
</project>

   The target "here" should be called depending on whether the target "testing" is succeeded or not.

Please let me know how do i achieve it.

Thanks,
Priya

Best Answer

Once nant finished its build it will execute a target specified by nant.onsuccess or nant.onfailure. This happens only once, so if you change the nant.onsucces / nant.onfailure properties it will have no effect.

As other posters stated for implementing conditional logic target dependencies, <if>, <trycatch>,<choose> and the <nant> and <call> tasks together with the if / unless attributes are better suited.