Fake JUnit test result for Atlassian Bamboo's plan
Hi! Today I going to share with you a little trick, which I used once for one of my Bamboo’s plan. First, Bamboo is a continuous integration server developed by Atlassian. (off topic: This is a holy war’s subject, but Bamboo is a Jenkins’ competitor.=) Anyway, I had to make a check of some parameter after build’s finish. The build was always successful, so Bamboo always mark it as “green”. But my goal was to set it “red” if some metrics was unacceptable. And after a conversation with my skilled colleagues I found a solution.
JUnit parser
So, the idea was clear enough! I just needed to create fake test result for my Bamboo’s Job! How it was. At first, I created a template like this. For “good” scenario:
<?xml version='1.0' encoding='utf-8'?>
<testsuite errors="0" failures="0" disabled="0" name="Name for a plan" tests="1" time="1"><testcase name="case name" status="run" time="0" errors="0"></testcase></testsuite>
For bad scenario:
<?xml version='1.0' encoding='utf-8'?>
<testsuite errors="1" failures="0" disabled="0" name="Name for a plan" tests="1" time="1"><testcase name="case name" status="run" time="0" errors="1"><error file="related file" line="1" message="Your message, that will be shown on Tests tab in bamboo's plan details." /></testcase></testsuite>
As you see, the difference is in “errors=”” statements and inside <testcase>
tags.
After that, I created a simple check (“script” task in bamboo) which generates the first file (named “fakereport.xml”) in case of success and the second in another case (with the same name). The checker is out of scope of this post, but it’s very simple. Anyway, after that I added a JUnit task,
made it a “Final Task”,
and configured it as following:
That’s all! Now when my check is OK I get a result like this:
And in case of failure - like this:
Ok, it’s not an obvious usage of JUnit parser, but a little trick.