Question

we do deployment using Jenkins job and Phing for builds. Our app is made on CakePHP. When I run Cake unit tests I got some errors (as expected).

/app/Console/cake test app AllQaTests --stderr --log-junit

But Phing doesn't perceive them and keeps building instead of stopping the process and marking the build as failed. Is there any elegant way of handling output of tests?

Now we use a separate script which scans test log and seeks for "FAILURE" word.

Was it helpful?

Solution

If your cake command outputs anything other than 0, it would be considered FAILURE by Jenkins, and the job will be marked accordingly.

To answer your question for searching console log for keywords, there is Text-finder plugin that allows to search console log and/or any other file for a RegEx, and mark the build as UNSTABLE or FAILED if found.

OTHER TIPS

I was about to do the same, but eventually tried to catch failed builds via Phing using returnProperty of ExecTask:

 <target name="caketest-local" description="Run CakePHP unit tests with PHPUnit and print human readable output.">
    <exec dir="${basedir}" executable="${basedir}/app/Console/cake" output="${logdir}/caketest.log" returnProperty="test_result">
        <arg line="test" />
        <arg line="--stderr"/>
        <arg line="--configuration=${basedir}/phpunit-coverage-text.xml" />
        <arg line="app" />
        <arg line="AllTests" />
    </exec>
    <if>
        <not>
            <equals arg1="${test_result}" arg2="0"/>
        </not>
        <then>
            <fail msg="Build FAILED! Check caketest.log for details"/>
        </then>
    </if>
</target>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top