CI build analysis: print log file errors

The generated HTML from CI builds so far only shows the number of
errors, but not the errors themselves. This is inconvenient, as this
means that developers have to go to the logs.

This commit modifies AnalyzeBuildLogs(), which already iterates the
entire file, to store the lines containing "error:" (as it would be
emitted by a compiler). The callers of AnalyzeBuildLogs() now also print
the analysis outcome in a more concise manner.

Also, change the return parameter of AnalyzeBuildLogs() to a tuple to make
the variable handling easier, and remove the unused warnings list.
This commit is contained in:
Robert Schmidt
2025-11-21 17:53:25 +01:00
parent 92980ceb72
commit bff0e53645
2 changed files with 14 additions and 12 deletions
+3 -3
View File
@@ -397,9 +397,9 @@ class Cluster:
# Analyze the logs # Analyze the logs
collectInfo = {} collectInfo = {}
for image, lf in log_files: for image, lf in log_files:
ret = cls_containerize.AnalyzeBuildLogs(image, lf) imgStatus, errors = cls_containerize.AnalyzeBuildLogs(image, lf)
imgStatus = ret['status'] info = f"Analysis of {os.path.basename(lf)}: {imgStatus=}, size {imageSize[image]}, {len(errors)} errors"
msg = f"size {imageSize[image]}, analysis of {os.path.basename(lf)}: {ret['errors']} errors, {ret['warnings']} warnings" msg = "\n".join([info] + errors)
HTML.CreateHtmlTestRowQueue(image, 'OK' if imgStatus else 'KO', [msg]) HTML.CreateHtmlTestRowQueue(image, 'OK' if imgStatus else 'KO', [msg])
status = status and imgStatus status = status and imgStatus
+11 -9
View File
@@ -86,9 +86,9 @@ def CreateTag(ranCommitID, ranBranch, ranAllowMerge):
return tagToUse return tagToUse
def AnalyzeBuildLogs(image, lf): def AnalyzeBuildLogs(image, lf):
errorandwarnings = {}
committed = False committed = False
tagged = False tagged = False
errors = []
with open(lf, mode='r') as inputfile: with open(lf, mode='r') as inputfile:
for line in inputfile: for line in inputfile:
lineHasTag = re.search(f'Successfully tagged {image}:', str(line)) is not None lineHasTag = re.search(f'Successfully tagged {image}:', str(line)) is not None
@@ -97,11 +97,13 @@ def AnalyzeBuildLogs(image, lf):
# the OpenShift Cluster builder prepends image registry URL # the OpenShift Cluster builder prepends image registry URL
lineHasCommit = re.search(r'COMMIT [a-zA-Z0-9\.:/\-]*' + image, str(line)) is not None lineHasCommit = re.search(r'COMMIT [a-zA-Z0-9\.:/\-]*' + image, str(line)) is not None
committed = committed or lineHasCommit committed = committed or lineHasCommit
errorandwarnings['errors'] = 0 if committed or tagged else 1 if re.search(r'error:|Errors|ERROR', line):
errorandwarnings['warnings'] = 0 errors.append(f"=> {line.strip()}")
errorandwarnings['status'] = committed or tagged status = (committed or tagged) and len(errors) == 0
logging.info(f"Analyzing {image}, file {lf}: {errorandwarnings}") logging.info(f"Analyzing {image}, file {lf}: {status=}, {len(errors)} errors")
return errorandwarnings for e in errors:
logging.info(e)
return status, errors
def GetImageName(ssh, svcName, file): def GetImageName(ssh, svcName, file):
ret = ssh.run(f"docker compose -f {file} config --format json {svcName} | jq -r '.services.\"{svcName}\".image'", silent=True) ret = ssh.run(f"docker compose -f {file} config --format json {svcName} | jq -r '.services.\"{svcName}\".image'", silent=True)
@@ -460,9 +462,9 @@ class Containerize():
# Analyze the logs # Analyze the logs
for name, lf in log_files: for name, lf in log_files:
ret = AnalyzeBuildLogs(name, lf) imgStatus, errors = AnalyzeBuildLogs(name, lf)
imgStatus = ret['status'] info = f"Analysis of {os.path.basename(lf)}: {imgStatus=}, size {allImagesSize[name]}, {len(errors)} errors"
msg = f"size {allImagesSize[name]}, analysis of {os.path.basename(lf)}: {ret['errors']} errors, {ret['warnings']} warnings" msg = "\n".join([info] + errors)
HTML.CreateHtmlTestRowQueue(name, 'OK' if imgStatus else 'KO', [msg]) HTML.CreateHtmlTestRowQueue(name, 'OK' if imgStatus else 'KO', [msg])
status = status and imgStatus status = status and imgStatus