My requirement is that, using waitfor condition, ant should periodically check if string "Build Successful" is displayed in log file. If the string is found, then particular action should be performed.
Here's an example of one way you might do this:
<target name="wait-for">
<waitfor maxwait="15" maxwaitunit="second" timeoutproperty="build.timeout">
<resourcecontains resource="build.log" substring="Build Successful" />
</waitfor>
<antcall target="build-success" />
</target>
<target name="build-success" depends="build-fail" unless="build.timeout">
<echo message="Success" />
</target>
<target name="build-fail" if="build.timeout">
<echo message="Fail" />
</target>
Use the resourcecontains
condition to look for the string in the named resource - in this case the file 'build.log'.
If it's not found in the allotted time, the build.timeout
property is set. There are two targets, one that is to be run
if the string is found, the other if not. The 'target' attributes if
, unless
, and depends
are used to make the if-else logic need. If you only need to take an action in the case of success or failure, you can simplify slightly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With