
Setting up a Jenkins agent node is a fundamental step for scaling your Jenkins automation and enabling distributed builds. Instead of overloading the main Jenkins controller, you can delegate build and test execution to separate machines, known as agents. This not only improves performance and stability of the controller but also allows you to run jobs on different operating systems or environments required by your projects.
The process begins by ensuring your target machine, which will serve as the agent node, meets the basic requirements, primarily having a compatible version of Java installed. Network connectivity between the controller and the potential agent is also crucial.
On the Jenkins controller, you navigate to the “Manage Jenkins” section and find the “Nodes” (or “Manage Nodes and Clouds”) configuration. Here, you can add a new node. You’ll give the agent a name and configure various settings. Key configurations include the number of executors (how many concurrent builds it can run), the remote root directory (where Jenkins will store workspace data on the agent), labels (used to assign specific jobs to specific agents), and the usage setting (controlling when Jenkins can use this node).
The most critical part of the setup is choosing and configuring the launch method, which determines how the Jenkins controller connects to and starts the agent process on the remote node. The two most common methods are Launch agent by connecting it to the controller (formerly JNLP) and Launch agents via SSH.
The SSH launch method is generally preferred for Linux/Unix-based agents. It requires Jenkins to have credentials (typically a username and password or an SSH key) to log into the agent machine. You specify the host name or IP address of the agent and the credentials. Jenkins then uses SSH to connect, copy the necessary agent executable, and launch it. This method is robust and leverages standard secure shell protocols.
The JNLP (Java Network Launch Protocol) method involves the agent machine initiating the connection back to the controller. This is often used when the controller cannot directly reach the agent (e.g., due to firewalls, but the agent can reach the controller) or for Windows agents. When configuring this, Jenkins provides commands or files (like a .jnlp
file) that you need to run on the agent machine. The agent process connects to a specific port on the controller to establish communication. Proper firewall configuration is necessary to allow this connection. For security, the agent connection often requires a secret key passed as a launch argument, linking the agent instance to the configured node on the controller.
Once the agent is configured and the launch method is set up on both sides, you need to verify that the connection is successful. The node list on the Jenkins controller will show the status of the agent. A successful connection means the agent is online and ready to execute builds. You can then configure your Jenkins jobs to run on this specific agent by restricting where the project can be run using the labels you assigned.
Properly setting up and managing Jenkins agents is vital for building a scalable and efficient CI/CD pipeline, distributing the workload and utilizing diverse environments for your builds.
Source: https://www.linuxtechi.com/setup-agent-node-in-jenkins/