2012-12-27 38 views
0

我想打电话给sendmail的一次RunTests完成,但其没有工作调用一个Ant任务陆续

<project name="Sample usage of Salesforce Ant tasks" basedir="." xmlns:sf="antlib:com.salesforce" default="RunTests"> 
    <!--******************************************* P R O P E R T Y F I L E *********************************************--> 
    <property file="build.properties"/> 
    <property environment="env"/> 
    <!--*******************************************RunTests***********************************************************--> 
    <target name="RunTests"> 
     <record name="RunTest.log" action="start"/> 
      <sf:compileAndTest username="${sf.backup_username}" password="${sf.backup_password}" serverurl="${sf.backup_serverurl}" > 
       <runTests Alltests="true"/> 
      </sf:compileAndTest> 
     <record name="RunTest.log" action="stop"/>  
    </target> 
    <target name="sendmail" depends="RunTests"> 
     <mail mailhost="email.corp.testcompany.com" mailport="25" subject="Run all tests - Sandbox 1337" messagefile="RunTest.log"> 
      <from address="[email protected]"/> 
      <replyto address="[email protected]"/> 
      <to address="[email protected]"/> 
     </mail> 
    </target>  
</project> 

我得到以下故障 -

构建失败 C:\ ANT_HOME \ QA_1337_TestRunner \构建.xml:8:失败:

有没有什么办法可以执行“sendemails”任务,即使前面的任务失败了。

回答

3

尝试运行

ant sendmail 

或更改默认的sendmail的

<project name="Sample usage of Salesforce Ant tasks" basedir="." xmlns:sf="antlib:com.salesforce" default="sendmail"> 

且简单地进行

ant 

编辑:

在快速查看salesforce docsf:compileAndTest任务后,我没有找到任何有用的信息,说明在测试和/或编译失败时如何避免目标执行失败。 (也许checkonly属性,但我不确定这是你需要的,如果你可以通过它通过蚂蚁任务)

所以我认为你必须处理外部目标执行失败。要做到这一点,你可以使用trycatch task from ant-contrib.

它看起来是这样的:

<trycatch property="foo" reference="bar"> 
    <try> 
    <record name="RunTest.log" action="start"/> 
     <sf:compileAndTest username="${sf.backup_username}" password="${sf.backup_password}" serverurl="${sf.backup_serverurl}" > 
      <runTests Alltests="true"/> 
     </sf:compileAndTest> 
    <record name="RunTest.log" action="stop"/> 
    </try> 

    <catch> 
    <echo>Got error while running compileAndTest</echo> 
    </catch> 

    <finally> 
    <mail mailhost="email.corp.testcompany.com" mailport="25" subject="Run all tests - Sandbox 1337" messagefile="RunTest.log"> 
     <from address="[email protected]"/> 
     <replyto address="[email protected]"/> 
     <to address="[email protected]"/> 
    </mail> 
    </finally> 
</trycatch> 

注意,您可以使用<catch>部分测试时无法发送专门的电子邮件。

propertyreference可用于获取有关故障(如果有的话)的信息。

+0

感谢您的回复,我认为我的构建失败这就是为什么它没有去电子邮件任务是吗? –

+0

@PfulfullaPatil这是正确的。这个答案解释了如何调用sendmail任务,它不能解决测试失败时发送邮件的问题。 –

+0

刚刚编辑了我的帖子,提供了解决此问题的可能解决方案。 – ben75