Using ant, Fail if the file contains "SUCCESS" string
Basically I want to check if the file contains "SUCC开发者_运维问答ESS" string. If string not found then ant has to exit with error message. Please help me on this. I tried many links but did'nt get this answer
You can do this with the Ant fail
task, assuming the file to check is called log.txt
:
<fail message="SUCCESS Found...failing">
<condition>
<resourcecontains resource="log.txt" substring="SUCCESS"/>
</condition>
</fail>
Here's an alternative approach, that you could adapt if you have more than one file to check.
<fileset id="success.file" dir="." includes="log.txt">
<contains text="SUCCESS"/>
</fileset>
<fail message="SUCCESS Found...failing">
<condition>
<resourcecount when="greater" count="0" refid="success.file" />
</condition>
</fail>
If none of the files in the fileset contain the string 'SUCCESS' then the fileset will be empty, so the build will not fail.
If you are on Linux, you could simply wrap the Get command with the exec target in Ant
This could also be useful
精彩评论