我有一个nant文件,用来构建我的项目。一旦构建成功,我将使用nant.onsuccess属性发送邮件。在这个nant.onsuccess中,我将调用下一批要构建的目标。但我需要根据从nant.onsuccess目标调用的这些目标集的成功或失败来发送邮件。
例如:
<?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.请让我知道我如何实现它。
谢谢,Priya
发布于 2012-10-11 18:00:56
一旦nant完成构建,它将执行由nant.onsuccess或nant.onfailure指定的目标。这种情况只发生一次,所以如果您更改nant.onsucces / nant.onfailure属性,它将不会产生任何影响。
正如实现条件逻辑的其他发贴者所说的那样,、、和任务以及if / unless属性更适合。
发布于 2010-01-09 09:27:52
首先要理解的是目标依赖如何控制执行。您可能只需使用依赖项就可以做很多您需要的事情。通读《NAnt基础知识page on targets》。
接下来,如果您必须根据某个特定任务是否失败而执行大量逻辑操作,那么您可以查看NAntContrib项目中的[trycatch](http://nantcontrib.sourceforge.net/release/latest/help/tasks/trycatch.html)任务,这将向NAnt添加许多有用的任务。与默认的nant.onfailure相比,trycatch任务允许更多的灵活性。
发布于 2012-07-06 23:49:03
我不确定这是否会有帮助。请看下面的链接。
我已经把一个示例构建文件放在一起了。
https://stackoverflow.com/a/11365488/1060656
<description>Sample Build Scripts</description>
<property name="nant.onsuccess" value="success" />
<property name="nant.onfailure" value="failure" />
<property name="tolist" value="youremail@email.com" />
<property name="cclist" value="youremail@email.com" />
<property name="emailsubject" value="" />
<target name="build" depends="init">
YOUR ACTUAL BUILD CODE GOES HERE
</target>
<target name="init">
<echo>
-----------------------------------------------------------------------------------------------------------------
TASK : INITIALIZE
-----------------------------------------------------------------------------------------------------------------
</echo>
<loadtasks assembly="nantcontrib-0.85/bin/NAnt.Contrib.Tasks.dll" />
<!-- http://www.basilv.com/psd/blog/2007/how-to-add-logging-to-ant-builds -->
<tstamp>
<formatter property="timestamp" pattern="yyMMdd_HHmm"/>
</tstamp>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<echo message="build.log.filename: ${build.log.filename}" />
<record name="${build.log.dir}/${build.log.filename}" action="Start" level="Verbose"/>
<echo message="Build logged to ${build.log.filename}"/>
<echo message="Build Start at: ${datetime::now()}" />
</target>
<!--http://www.mail-archive.com/nant-users@lists.sourceforge.net/msg02485.html-->
<target name="success" depends="successresult,sendemail">
<echo>${emailsubject}</echo>
</target>
<!--http://www.mail-archive.com/nant-users@lists.sourceforge.net/msg02485.html-->
<target name="failure" depends="failureresult,sendemail">
<echo>${emailsubject}</echo>
</target>
<target name="successresult" >
<echo>
BUILD FAILED . CHANGE SUBJECT
</echo>
<property name="emailsubject" value="Web Integration DEV Build : SUCCESS !!!" />
</target>
<target name="failureresult" >
<echo>
BUILD FAILED . CHANGE SUBJECT
</echo>
<echo message="Task Start at: ${datetime::now()}" />
<property name="emailsubject" value="Web Integration DEV Build : FAILED !!! :)" />
</target>
<target name="sendemail" >
<echo>
-----------------------------------------------------------------------------------------------------------------
SENDING EMAIL
-----------------------------------------------------------------------------------------------------------------
</echo>
<echo message="Task Start at: ${datetime::now()}" />
<echo>${emailsubject}</echo>
<echo>Sending Email</echo>
<echo>Attaching File : ${build.log.dir}/email_${build.log.filename}</echo>
<echo>Attaching File : ${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}</echo>
<!-- Flush is very important before you copy -->
<record name="${build.log.dir}/${build.log.filename}" action="Flush" level="Verbose"/>
<sleep milliseconds="1000" />
<!-- make a copy -->
<copy file= "${build.log.dir}/${build.log.filename}" tofile="${build.log.dir}/email_${build.log.filename}" />
<mail
from="${email.from}"
tolist="${email.to}"
mailhost="${email.host}"
message="${emailsubject}"
subject="${emailsubject}"
>
<attachments>
<include name="${build.log.dir}/email_${build.log.filename}" />
<include name="${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}" />
</attachments>
</mail>
</target>
https://stackoverflow.com/questions/1599105
复制相似问题