Ant 调用一个接一个的蚂蚁任务

Ant 调用一个接一个的蚂蚁任务,ant,Ant,我想在运行测试完成后调用sendmail,但它不起作用 <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 *****************

我想在运行测试完成后调用sendmail,但它不起作用

<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="user2@testcompany.com"/>
            <replyto address="user2@testcompany.com"/>
            <to address="user2@testcompany.com"/>
        </mail> 
    </target>       
</project>

我遇到了以下失败-

构建失败 C:\ANT\u HOME\QA\u 1337\u TestRunner\build.xml:8:失败:

是否有任何方法可以执行“发送电子邮件”任务,即使之前的任务失败。

尝试运行

ant sendmail
或者将默认设置更改为sendmail

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

在快速查看任务sf:compileAndTest之后,我没有找到任何关于如何在测试和/或编译失败时避免目标执行失败的有用信息。(可能是属性,但我不确定这是您需要的,也不确定您是否可以通过ant任务传递它)

因此,我认为您必须从外部处理目标执行失败。为此,您可以使用

它将如下所示:

<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="user2@testcompany.com"/>
        <replyto address="user2@testcompany.com"/>
        <to address="user2@testcompany.com"/>
    </mail>
  </finally>
</trycatch>

运行compileAndTest时出错
请注意,当测试失败时,您可以使用
部分发送特殊电子邮件

可以使用
属性
参考
获取有关故障的信息(如果有)。

尝试运行

ant sendmail
或者将默认设置更改为sendmail

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

在快速查看任务sf:compileAndTest之后,我没有找到任何关于如何在测试和/或编译失败时避免目标执行失败的有用信息。(可能是属性,但我不确定这是您需要的,也不确定您是否可以通过ant任务传递它)

因此,我认为您必须从外部处理目标执行失败。为此,您可以使用

它将如下所示:

<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="user2@testcompany.com"/>
        <replyto address="user2@testcompany.com"/>
        <to address="user2@testcompany.com"/>
    </mail>
  </finally>
</trycatch>

运行compileAndTest时出错
请注意,当测试失败时,您可以使用
部分发送特殊电子邮件


属性
参考
可用于获取有关故障(如果有)的信息。

我认为您需要查看
故障属性
haltOnFailure
属性

此线程答案中的更多信息:

我认为您需要查看
failureProperty
haltOnFailure
属性

此线程答案中的更多信息:

谢谢你的回复,我想我的构建失败了,这就是为什么它没有进入电子邮件任务的原因,对吗?@PrafullaPatil,对。这个答案解释了如何调用sendmail任务,它不能解决测试失败时发送邮件的问题谢谢你的回复我认为我的构建失败了这就是为什么它不能转到电子邮件任务的原因是吗?@prafullapil这是对的。这个答案解释了如何调用sendmail任务,它不能解决测试失败时发送邮件的问题