Overview

Problem

Jenkins inbound (JNLP) agents on Windows typically require:

  1. A user to be logged in running java -jar agent.jar in a terminal
  2. A scheduled task workaround that is fragile and lacks proper service lifecycle management
  3. Manual restarts after reboots or crashes

Solution

JenkinsAsService wraps the Jenkins inbound agent connection inside a native Windows Service built with .NET 10. The service:

  1. Reads configuration from appsettings.json
  2. Validates all settings (Jenkins URL with explicit port, agent secret, Java path)
  3. Tests TCP connectivity to the Jenkins controller
  4. Downloads agent.jar using ETag-based conditional GET (skips on 304 Not Modified)
  5. Launches the Java agent process with async output parsing and secret redaction
  6. Monitors the agent via an event-driven watchdog with exponential backoff auto-recovery

Key Benefits

How It Works

flowchart TD
    A[Windows Service Manager] -->|Calls ExecuteAsync| B[Validate Settings]
    B --> C{Settings OK?}
    C -->|No| D[Log Error & Stop]
    C -->|Yes| E[Resolve Java Path]
    E --> F[Test TCP Connectivity]
    F -->|Fail| D
    F -->|Pass| G["Download agent.jar (ETag cached)"]
    G --> H[Start Java Process]
    H --> I[Watchdog Loop]
    I -->|process.Exited or 60s timer| J{Process exited?}
    J -->|No — stable 60s| K[Reset retry counter]
    K --> I
    J -->|Yes| L["Log SEVERE count, Backoff, Re-download, Restart"]
    L --> I