Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Build Logs - Accessing a Previous Step's Log #3693

PaulR ·
I've been trying to write a step that you can put at the end of any build to have it provide some context on the build failures that have occurred.
The Analyzer step would: [list]
1. Scan all previously finished steps in a build
2. Identify any that have failed
3. Get the complete log for the failed steps
4. Retrieve a list of Regex's from a Database
5. Run each regex over the log file to identify known failure patterns.
6. If any of the regex's are found, use a format string and feed that information back to the step as an artifact.
[/list:u]
I can do everything in the list except for step 3. (Although I haven't tested 6 yet)
The problem I'm having is accessing the log output from a previously finished step doesn't seem to be possible within the context of a subsequent step.

I've tried several things to get my hands on the previous steps' logs all to no avail.
[list]
1. new BuildLog(build.id, step.path); stepLog.getTextInputStream("\n", true);[list]
even with byte by byte reading, the stream size is 0 and I never get anything from it.
(being an input stream, this doesn't surprise me)
I can get the name from the stepLog, so I know it's "there"[/list:u]
2. build.renderLogAsHtml(true) & build.renderLogAsText(true)[list]
Both produce 0-length strings.[/list:u]
3. build.getLogUrl(step.getName())[list]
The URL is generated, but attempts to access it come up with an error: Invalid step path: Test Failure[/list:u]
4. new BuildLog(build.id);[list]
The build log is empty as it's still "live".[/list:u]
5. DefaultLivelogManager.instance.getLiveLog(build.id, step.path, 0);[list]
Live logs are only available for the overall build, and the current step (The Analyzer).
All "finished" steps do not have a "live log" available to them.[/list:u]
6. build.getLogFile(); [list]
Errors with "The system cannot find the path specified" as the script is running on a node, not the master.[/list:u]
[/list:u]
The only interface I can't seem to exercise is: step.renderLogAsText[list]
It requires a "BuildLogEntry", which I can't find an interface to other than the LiveLog.[/list:u]

A little help, if you please!
  • replies 1
  • views 1467
  • stars 0
robinshen ADMIN ·
A running step can not access the build log. Do this task in the post-build script (advanced setting of the configuration) instead. You may open the build log file directly: it is a object stream of type "BuildLogEntry", and if you read null value, it is the end of stream. Then in the BuildLogEntry object you can check things such as step, message, log level etc. Also you may copy files to artifacts directly to publish artifacts at this stage. Make sure to call build.getPublishDir() always and concatenate it with appropriate sub dirs or files to get build log path or artfiacts path.