Qarion
Qarion

Reputation: 83

printing list of failed tests in jenkins in post build script

I have a jenkins job that executes some junit tests, and a post build step that calls a bash script if tests fail(actually checks if the log contains "Tests in error:"). The script will then send some text(making use of some of jenkins' environment variables) to a skype bot.

Now I want to have the bot say which tests actually failed. I've been looking through the plugin and google but so far I've come up with no way to tell which tests fail. Is there a way to pass the failed tests to the script, or set environment vars after/durings the build?

Upvotes: 4

Views: 5221

Answers (1)

Dennis S.
Dennis S.

Reputation: 2121

We have a jenkins job that executes unit tests, and has a post build step to "Publish JUnit test report".

That gives us a page that shows test results, including failed tests. One option for your script is to fetch that page and screen scrape the failed test names out of it (they're buried in a "showFailuresLink" function in our installation).

The page is also accessible via the REST API. I played with it a little and found a request like this:

http://host:7098/jenkins/job/ExecuteUnitTests/166/testReport/api/json?pretty=true&tree=suites[cases[className,name,age,status]]

gives a result like this:

{
  "suites" : [
    {
      "cases" : [
        {
          "age" : 0,
          "className" : "com.e.authentication.SimpleAuthenticationInfoTest",
          "name" : "testGetCredentialKeys",
          "status" : "PASSED"
        },
        {
          "age" : 0,
          "className" : "com.e.authentication.SimpleAuthenticationInfoTest",
          "name" : "testGetExpirationInterval",
          "status" : "PASSED"
        },
...

Simple enough to parse out the entries where age is > 0 or status != PASSED. There may be a way to refine the request even further to get just what you want, but I'm out of time to play with it.

Upvotes: 6

Related Questions