You’ll need to decide how the agent will be launched. Here are your options--

Launch Agents via SSH

Launch Agent by Connecting it to the Controller


1. Launch Agents via SSH

This method allows Jenkins to connect to an agent machine through SSH and start the agent process on it. This method is commonly used for Unix-based systems. Here’s how it works:

  • Preconditions:
    • The agent machine must have SSH access enabled.
    • Jenkins must have proper SSH credentials for the agent (either username/password or SSH keys).
    • Java must be installed on the agent machine, as Jenkins runs the agent through a Java process.
  • Setup Process:
    1. In Jenkins, navigate to "Manage Jenkins" → "Manage Nodes and Clouds" → "New Node".
    2. Create a new node and configure its parameters (name, number of executors, labels, etc.).
    3. Set the Launch Method to “Launch agents via SSH”.
    4. Provide the agent’s host details (IP or hostname).
    5. Configure the SSH credentials (either by choosing from existing credentials or adding new ones).
    6. Jenkins will use SSH to remotely execute the agent.jar file, which will connect back to the Jenkins controller.
    7. Once the connection is successful, the agent will be available for jobs to run.

Advantages:

  • Easy to set up for Unix/Linux-based environments.
  • Centralized control of agents from the Jenkins UI.

Challenges:

  • Requires Java to be installed on the agent machine.
  • SSH access needs to be secure, and handling credentials properly is essential.

2. Launch Agent by Connecting it to the Controller

This method involves manually starting the agent on the agent machine and letting it connect to the Jenkins controller. It’s commonly used when SSH is not possible or preferred.

  • Preconditions:
    • The agent machine should be able to communicate with the Jenkins controller over the network.
    • Java must be installed on the agent machine.
  • Setup Process:
    1. On the agent machine, download the agent.jar file from the Jenkins controller. This can typically be found under Jenkins URL → "Manage Jenkins" → "Manage Nodes" → "Click on the agent" → "Launch agent".
    2. Once connected, the agent will be listed under the "Manage Nodes" section of Jenkins and ready to execute jobs.

Start the agent manually by running a command like:

java -jar agent.jar -jnlpUrl <Jenkins-Controller-URL>/computer/<Node-Name>/slave-agent.jnlp -secret <Secret-Value> -workDir "<Agent-Work-Dir>"

This command establishes a connection between the agent and the controller.

Advantages:

  • Useful when SSH is not available or feasible.
  • Allows manual control over the agent's lifecycle.

Challenges:

  • Requires manual intervention to start the agent.
  • Network configuration needs to allow the agent to communicate with the controller.

Summary

  • Launch via SSH is more automated and suitable for Unix-based systems with SSH access.
  • Launch by Connecting to the Controller gives you more manual control, often used in scenarios where SSH isn't an option or for Windows-based systems.