-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed the truncate summary to cut build logs from top #272
Merged
timja
merged 13 commits into
jenkinsci:master
from
sarahdeitke:sarah-truncate-summary-build-log
Feb 16, 2025
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a7c1f59
kind of working
sarahdeitke e3fef67
testing
sarahdeitke 861bcf5
revert text change
sarahdeitke 01fd797
adjust tests
sarahdeitke b29ecd3
checkstyle
sarahdeitke 7a18a81
fix spotbugs
sarahdeitke 1298762
move implementation to flowexecutionanalyzer
sarahdeitke 88f7eb2
move logic to the flow execution analyzer
sarahdeitke c48c521
fix lint
sarahdeitke a634486
test that end log exists
sarahdeitke 82a224c
adjust script
sarahdeitke a169226
crossplatform support, bug fix
sarahdeitke 7ebe654
add buffer, additional assertion
sarahdeitke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,6 +297,60 @@ public void shouldPublishStageDetailsWithoutLogsIfRequested() { | |
}); | ||
} | ||
|
||
/** | ||
* Test that log messages are properly truncated when they exceed the maximum size limit. | ||
*/ | ||
@Test | ||
public void shouldTruncateLogsWhenExceedingMaxSize() { | ||
getProperties().setApplicable(true); | ||
getProperties().setSkipped(false); | ||
getProperties().setName("Test Status"); | ||
getProperties().setSuppressLogs(false); | ||
WorkflowJob job = createPipeline(); | ||
|
||
// Create a pipeline that generates a large log output | ||
job.setDefinition(new CpsFlowDefinition("" | ||
+ "node {\n" | ||
+ " stage('Large Log Stage') {\n" | ||
+ " // Generate a large log using Jenkins' built-in commands\n" | ||
+ " def logContent = (1..1000).collect { i ->\n" | ||
+ " \"Line ${i}: This is a very long log line that will be repeated many times to test truncation. Adding some extra system information here.\"\n" | ||
+ " }.join('\\n')\n" | ||
+ " // Use writeFile and bat/sh based on platform\n" | ||
+ " writeFile file: 'large_log.txt', text: logContent\n" | ||
+ " if (isUnix()) {\n" | ||
+ " sh 'cat large_log.txt && exit 1'\n" | ||
+ " } else {\n" | ||
+ " bat 'type large_log.txt && exit /b 1'\n" | ||
+ " }\n" | ||
+ " error('Pipeline failed with large logs')\n" | ||
+ " }\n" | ||
+ "}", true)); | ||
|
||
buildWithResult(job, Result.FAILURE); | ||
|
||
List<ChecksDetails> checksDetails = getFactory().getPublishedChecks(); | ||
|
||
// Get the final check details which should contain the truncated logs | ||
ChecksDetails details = checksDetails.get(checksDetails.size() - 1); | ||
assertThat(details.getStatus()).isEqualTo(ChecksStatus.COMPLETED); | ||
assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.FAILURE); | ||
assertThat(details.getOutput()).isPresent().get().satisfies(output -> { | ||
assertThat(output.getSummary()).isPresent().get().satisfies(summary -> { | ||
// Verify the log section exists and is truncated | ||
assertThat(summary).contains("<details>"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you also check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
assertThat(summary).contains("Build log"); | ||
assertThat(summary).contains("Build log truncated."); | ||
assertThat(summary).doesNotContain("Line 1:"); // Should be truncated from the start | ||
assertThat(summary).contains("exit"); // Should see the exit command at the end | ||
// Verify the truncation message appears at the start of the log section | ||
assertThat(summary).matches(Pattern.compile(".*<summary>Build log</summary>\\s+\\n```\\s*\\nBuild log truncated.\\n\\n.*", Pattern.DOTALL)); | ||
// Verify the total size is within limits | ||
assertThat(summary.length()).isLessThanOrEqualTo(65_535); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Validates that a simple successful pipeline works. | ||
*/ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be approx -70 (or even -100 to be safe?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are looking at an older version of the code, I have included the log format in the max size. I added an additional 30 character buffer to be safe though