Skip to content

Conversation

@zendesk-abhijeet
Copy link
Contributor

@zendesk-abhijeet zendesk-abhijeet commented Dec 18, 2025

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:

  • Default configuration (option is disabled by default).
  • Configuration round-trip (UI to backend and back).
  • Log capture only when the option is enabled.
  • Aggregation of stdout and stderr.
  • Newline normalization to “ || ” and trimming behavior.
  • No-op when init script output is empty.
    All new and existing tests pass locally (clean build and test run).
EC2_Plugin_Patch_UT

Functional verification on a Jenkins instance

  • Environment: Verified on our Jenkins installation with the updated EC2 plugin build. The change was tested by launching new EC2 agents configured with an init script.
  • Behavior with option enabled: When “Collect init script logs” was enabled, the init script’s stdout/stderr were captured in Jenkins system logs as a single-line entry per execution block (newline characters normalized to “ || ”). Logs remained available in system logs after the agent terminated, enabling post-mortem debugging.
EC2_Plugin_InitScript_Log_STDOUT EC2_Plugin_InitScript_Log_STDERR

UI verification

  • Verified the new “Collect init script logs” checkbox appears in the EC2 agent/Template configuration with an explanatory help text.
  • Confirmed default state is unchecked, and the setting persists correctly after save (round-trip).
  • Manually tested with the option both checked and unchecked to ensure consistent behavior and no visual regressions or validation issues in the configuration screen.
EC2_Plugin_Patch_UI

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@zendesk-abhijeet zendesk-abhijeet force-pushed the abhijeet/capture-init-script-logs branch from 88c0960 to 027d314 Compare December 18, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant