My friend Ghassan came up with this good example of how you can parse the contents of a text file (say after running a Jenkins build) and look inside the for an error so you can fail the build.

CheckFailure.proj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
	<PropertyGroup>
		<SummaryReportName>SummaryReport.html</SummaryReportName>
	</PropertyGroup>

	<Target Name="Default">
	  <CallTarget Targets="CheckJmeterForFailure" />
	</Target>

	<Target Name="CheckJmeterForFailure">
		<Message Text="Check summary report for any failure" />
		<ReadLinesFromFile File="$(SummaryReportName)">
			<Output TaskParameter="Lines" PropertyName="SummaryReportOutput" />
		</ReadLinesFromFile>
		<Error Condition="$(SummaryReportOutput.Contains('Failure'))" Text="One of the JMeter tests failed" />
	</Target>
</Project>

Basically you point to the file you want to parse, read it, and then look for the error condition. Thx Ghassan!

Advertisement