I was asked by someone how they can retrieve test results somehow from Bamboo, because they have a separate, custom dashboard they use for displaying test results.
I know Atlassian has a REST API for all of their main products, is it possible to get test results back using it?
Yes, it is possible and not too difficult. The main caveat is that the smallest (and largest) group of test results you can retrieve is job sized.
Here's the latest documentation on Bamboo's API:
To retrieve results, we'll use curl (though Python and many other tools are available) and xmllint to output the results in
Our example Bamboo server's base rest url is:
https://bamboo.company.com/rest/api/latest/We can get build results back by adding
/result/projectkey-buildkey-job/buildnumberto the url.
Test results will be brief until we expand the test results, so we add
?expand=testResults.allTeststo the end of that. If you're just looking for failures, or a slew of other filters, they have that too.
It defaults to xml output I believe, but you can output JSON format by adding .json to the end of the url, before the arguments. Word is that JSON will be deprecated at some point, but for now you can still get results back that way. I'll show how in a minute.
I don't want to specify the build number, I just want the latest results, and Atlassian supports "latest" as the build number. So, here's our complete url, using a made up plan with unit tests as our example:
If you want JSON output, it would be this:
Now, it outputs a huge block of unformatted xml by default. If you want to to look nice, we pass it through xmllint, by appending this to the end:
| xmllint --format -By default, anonymous is disabled in our install, so we need to pass authentication. The simplest example is using basic auth, so the complete command line would be this, using your username and password:
curl -u username:password https://bamboo.company.com/rest/api/latest/result/PLAN-STAGE-JOB/latest?expand=testResults.allTests | xmllint --format -And it outputs something like this:
There's much more you can do beyond retrieving test results. You can also use this to kick off plans, get deployment results, etc. And, each release of Bamboo expands the REST API.
-Kelly G. Schoenhofen