Added an option to collect init script logs #1988
Open
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.
Optional collection of init script execution logs
Summary
Adds an optional setting, “Collect init script logs,” to capture EC2 agent init script output in Jenkins system logs.
Ensures init script output persists after agent termination and can be forwarded to observability platforms.
Problem
Init script output currently appears only in the agent logs during startup and is not recorded in Jenkins system logs.
When an agent terminates, those logs are lost. This makes it difficult to debug non–job-related issues caused by improper agent initialization.
Solution
Introduce an optional, configurable parameter: “Collect init script logs.”
When enabled, the plugin captures the init script’s stdout/stderr and writes it to Jenkins system logs so the data remains available after the agent lifecycle ends and can be exported to external observability systems.
Implementation details
Log normalization: newline characters in the init script output are deliberately replaced with “ || ” so each execution block is recorded as a single system log entry. This:
Keeps logs compact and easier to scan
Avoids large bursts of multi-line entries in system logs
Scope: only affects init script execution logs. Job logs and other logging remain unchanged.
Backward compatibility: the option is off by default; there is no behavior change unless explicitly enabled.
Testing done
Added unit tests covering:
All new and existing tests pass locally (clean build and test run).
Functional verification on a Jenkins instance
UI verification
Submitter checklist