Skip to content

LarrysGIT/Extract-Jenkins-Raw-Log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Extract-Jenkins-Raw-Log

So, how to extract plain text log from Jenkins raw log file?

Digging into Jenkins source code, it gives the answer

https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/console/ConsoleNote.java

 * {@link ConsoleNote}s are serialized and gzip compressed into a byte sequence and then embedded into the
 * console output text file, with a bit of preamble/postamble to allow tools to ignore them. In this way
 * {@link ConsoleNote} always sticks to a particular point in the console output.

Look further, the AMBER strings are defined. https://en.wikipedia.org/wiki/ANSI_escape_code

    public static final String PREAMBLE_STR = "\u001B[8mha:";
    public static final String POSTAMBLE_STR = "\u001B[0m";

An example

I copied the first line of a test pipeline build log of my local installed Jenkins

Started by user [8mha:////4H+H6gi+RzqRXgbuxDkiDNvJYq3pMCu17+YXxGOB+mHbAAAAlx+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAzWEgZu/dLi1CL9xJTczDwAj6GcLcAAAAA=[0madmin

The line can be split to following parts,

Part Value
{A string} Started by user
{PREAMBLE_STR} \u001B[8mha:
{BASE64_STR} ////4H+H6gi+RzqRXgbuxDkiDNvJYq3pMCu17+YXxGOB+mHbAAAAlx+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAzWEgZu/dLi1CL9xJTczDwAj6GcLcAAAAA=
{POSTAMBLE_STR} \u001B[0m
{A string} admin
  • Convert the {BASE64_STR} to bytes

  • Trim the first 40 bytes (#1)

  • Output to a .gz file, or stream whatever preferred. use gzip method to extract

The extracted file, file command tells me it's Java serialization data, version 5, surely you can see plain text from it.

Samplelog

A sample of log file copied from my local installed Jenkins

Decode-JenkinsRawLog.ps1

A powershell implementation

#> & .\Decode-JenkinsRawLog.ps1

Decode-JenkinsRawLog.py

A python implementation

#> python3 Decode-JenkinsRawLog.py

About

Extract/Decrypt/Decode jenkins logs whatever you want to call it.

Resources

Stars

Watchers

Forks