0

society! I need your help. I'm QE and I need to solve one problem, what happened to me. I need to find the way, how I can parse the console output with a number of tests(total and fail) and put this on the subject of my email. I tried log parser, not works for me or I don't have idea how to use it

2 Answers2

0

Instead of trying to parse logs, I think you should go about it with a different approach. I believe Jenkins (JUnit) stores the test results as artefacts. I'm sure there's a plugin that will let Jenkins mail you the test results in HTML format upon failure -- in fact I'm almost sure Jenkins can do this out of the box.

Stephan Henningsen
  • 3,665
  • 1
  • 22
  • 29
0

Instead of using a jenkins plugin, you could try downloading the logs (use .../path/to/build/consoleText instead of .../path/to/build/console to remove timestamps and other things). You can use cURL (or wget for linux) to download it as a txt file and parse it as you would any other plaintext file.

If you don't want to download it, and you have access to do things on master, see this SO answer.

Jenkins stores the console log on master. If you want programmatic access to the log, and you are running on master, you can access the log that Jenkins already has, without copying it to the artifacts or having to GET the http job URL.

From http://javadoc.jenkins.io/archive/jenkins-1.651/hudson/model/Run.html#getLogFile(), this returns the File object for the console output (in the jenkins file system, this is the "log" file in the build output directory).

In my case, we use a chained (child) job to do parsing and analysis on a parent job's build.

When using a groovy script run in Jenkins, you get an object named "build" for the run. We use this to get the http://javadoc.jenkins.io/archive/jenkins-1.651/hudson/model/Build.html for the upstream job, then call this job's .getLogFile().

Added bonus; since it's just a File object, we call .getParent() to get the folder where Jenkins stores build collateral (like test xmls, environment variables, and other things that may not be explicitly exposed through the artifacts) which we can also parse.

Double added bonus; we also use matrix jobs. This sometimes makes inferring the file path on the system a pain. .getLogFile().getParent() takes away all the pain.

kirkpatt
  • 625
  • 5
  • 21