The Jenkins JNLP agent failed to connect because the Jenkins controller, acting as the server, could not establish a persistent WebSocket or TCP connection with the agent process, which was trying to register itself.
Common Causes and Fixes:
-
Network Firewall Blocking Ports: The most frequent culprit is a firewall, either on the Jenkins controller, the agent host, or an intermediate network device, blocking the necessary ports. JNLP agents typically connect on port 50000 (for outbound connections from agent to controller) or the controller’s port (usually 8080 or 8443) if the agent is initiating a connection that is then redirected.
- Diagnosis: On the agent machine, try to
telnetto the Jenkins controller’s IP/hostname and port. From the controller machine, try totelnetto the agent’s IP/hostname and port 50000.
If# On agent machine, to controller's web port (e.g., 8080) telnet <jenkins_controller_hostname_or_ip> 8080 # On controller machine, to agent's JNLP port (e.g., 50000) telnet <jenkins_agent_hostname_or_ip> 50000telnethangs or immediately disconnects, the port is likely blocked. - Fix: Open the relevant ports in your firewalls. For example, on
firewalldon the controller:
And on the agent (if it’s listening on 50000):sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent sudo firewall-cmd --reload
Alternatively, if usingsudo firewall-cmd --zone=public --add-port=50000/tcp --permanent sudo firewall-cmd --reloadufw:sudo ufw allow 8080/tcp sudo ufw allow 50000/tcp sudo ufw reload - Why it works: This explicitly permits network traffic on the ports Jenkins uses for JNLP communication, allowing the handshake and data exchange to occur.
- Diagnosis: On the agent machine, try to
-
Incorrect JNLP Agent URL in
jenkins-agent.jnlp: Thejenkins-agent.jnlpfile downloaded from Jenkins contains the URL the agent should use to connect. If this URL is mistyped, points to the wrong controller, or uses an incorrect protocol (HTTP vs. HTTPS), the connection will fail.- Diagnosis: Download the
jenkins-agent.jnlpfile from the agent configuration page in Jenkins. Open it with a text editor and examine the<jnlp>tag, specifically thecodebaseattribute, and the<application-content>tag.
The<jnlp spec="1.0+" codebase="http://your-jenkins-controller:8080/"> <information> <title>Agent for Jenkins</title> <vendor>Jenkins Project</vendor> </information> <resources> <j2se version="1.8+" href="http://java.sun.com/products/autodl/j2se"/> <jar href="agent.jar" main="true"/> </resources> <application-desc main-class="hudson.remoting.jnlp.Main"> <argument>your-jenkins-controller:50000</argument> </application-desc> </jnlp>codebaseshould match your Jenkins controller’s URL, and the argument after<argument>is the host and port the agent attempts to connect to. - Fix: Ensure the
codebaseURL and the argument in thejenkins-agent.jnlpfile are correct. If they are wrong, go to "Manage Jenkins" -> "Nodes" -> click on the agent -> "Configure" -> "Agent launch method" and correct the "Jenkins URL" or the agent configuration itself. Then re-download thejenkins-agent.jnlpfile. - Why it works: Providing the correct target URL ensures the agent process knows where to initiate its connection attempt.
- Diagnosis: Download the
-
Agent Process Not Running or Crashed: The agent process might not have started, or it might have crashed shortly after starting due to an unhandled exception or resource issue.
- Diagnosis: Check the process list on the agent machine for
javaprocesses that look like the Jenkins agent. Look foragent.jarin their command line. Also, check the agent’s log file for any errors.
If no such process is found, or if it’s short-lived, investigate why it’s not starting or crashing. Check the output of the command used to launch the agent.# On agent machine ps aux | grep java # Look for a java process running agent.jar - Fix: Ensure the command to launch the agent is correct and that the necessary Java runtime environment (JRE) is installed and accessible. For example, if launching manually:
If it’s running as a service, check the service status and logs.java -jar /path/to/agent.jar -jnlpUrl http://your-jenkins-controller:8080/computer/your-agent-name/jenkins-agent.jnlp -secret <your-secret-key> - Why it works: This ensures the agent process is actively running and listening for connections from the controller.
- Diagnosis: Check the process list on the agent machine for
-
JNLP Secret Mismatch or Expired: The secret key used to authenticate the agent with the controller might be incorrect, or if it was generated a long time ago and the agent configuration was re-saved without updating the secret, it could be stale.
- Diagnosis: Compare the secret key shown in the Jenkins agent configuration page ("Manage Jenkins" -> "Nodes" -> agent -> "Configure") with the secret key being used by the agent process (often passed as a command-line argument or in an agent configuration file).
- Fix: Copy the current secret key from the Jenkins UI and update the agent’s startup command or configuration file with the correct, current secret. If you don’t see a secret, click "Show".
# Example using command-line secret java -jar agent.jar -jnlpUrl http://your-jenkins-controller:8080/computer/your-agent-name/jenkins-agent.jnlp -secret abcdef1234567890abcdef1234567890 - Why it works: The secret key is a one-time password or shared secret used for initial authentication. A correct, current secret allows the agent to prove its identity to the controller.
-
Jenkins Controller Overloaded or Unresponsive: If the Jenkins controller itself is under heavy load, experiencing high CPU, memory, or disk I/O, it might be too slow to accept new JNLP connections or keep existing ones alive.
- Diagnosis: Monitor the Jenkins controller’s system resources (CPU, memory, disk I/O). Check Jenkins system logs for any signs of slowness,
OutOfMemoryError, or long garbage collection pauses. Also, check the Jenkins controller’s own network connectivity and responsiveness. - Fix: Address the root cause of the controller’s load. This might involve adding more resources (CPU, RAM), optimizing Jenkins jobs, increasing heap size for the Jenkins JVM, or moving Jenkins to more powerful hardware. For example, increasing heap size by adding
-Xmx4gto the Jenkins startup script (e.g.,jenkins.shorjenkins.xml). - Why it works: A healthy and responsive Jenkins controller can dedicate resources to managing agent connections, ensuring reliable communication.
- Diagnosis: Monitor the Jenkins controller’s system resources (CPU, memory, disk I/O). Check Jenkins system logs for any signs of slowness,
-
Java Version Incompatibility (Agent vs. Controller): While less common for JNLP, significant differences in Java versions between the controller and the agent, or issues with the Java runtime on the agent, can sometimes cause connection problems.
- Diagnosis: Check the Java version on the Jenkins controller and the agent machine.
Ensure both are running a supported and compatible Java version (e.g., Java 8 or 11 are common).# On controller and agent java -version - Fix: Install or configure the agent to use a compatible Java version. Jenkins typically requires Java 8 or higher for the controller and recommends a compatible version for agents. Ensure
JAVA_HOMEis set correctly on the agent if launching manually or via a service. - Why it works: Consistent and compatible Java runtimes reduce the chances of low-level communication or serialization issues between the controller and agent.
- Diagnosis: Check the Java version on the Jenkins controller and the agent machine.
-
Proxy Configuration Issues: If the Jenkins controller or agent is behind a proxy server, incorrect proxy settings can prevent the JNLP connection from being established.
- Diagnosis: Examine the Jenkins controller’s JVM proxy settings (e.g.,
http.proxyHost,https.proxyHost,noProxy) and the agent’s environment variables or JVM arguments for proxy settings. - Fix: Ensure the proxy settings are correctly configured for both the controller and the agent. For the agent, you might need to set JVM system properties when launching it:
For the controller, these are usually set injava -Dhttp.proxyHost=your.proxy.com -Dhttp.proxyPort=8080 -jar agent.jar ...jenkins.xmlorjenkins.sh. - Why it works: Correct proxy configuration allows the JNLP connection to traverse the network infrastructure as intended.
- Diagnosis: Examine the Jenkins controller’s JVM proxy settings (e.g.,
After fixing these issues, the next error you’ll likely encounter is a "JNLP agent disconnected" error if the agent was previously connected but the underlying issue caused it to drop.