jenkinsjenkins-agent

I am trying to learn Jenkins and have a few questions regarding the concept of Jenkins agents


I will try to explain what I understand about the Jenkins agents, please correct me wherever I am wrong or could do better.

  1. Any machine that can run Java can be an agent.
  2. Agent can be bare metal or a be running in a virtual machine or can be a Docker container.
  3. Agent can be local or remote.
  1. To create a remote agent we have to use the option "Launch agent via SSH"
  2. The option "Launch agent by connecting it to the controller" is used to create local agents.

Before posting this question on stackoverflow I asked these same questions to Google Bard.

For the 5th statement I received this following comment from Bard:

  1. "Launch agent by connecting it to the controller":

Not limited to local agents: This option can be used for both local and remote agents. It allows the controller to initiate the agent launch and manage its configuration dynamically.

Alternative Launch Method: This contrasts with manual agent launch, where you install and configure the agent software yourself.

Please help me understand, how can I use the option "Launch agent by connecting it to the controller" to create remote agents. I have this confusion because after creating the agent with this option, I get the following command:

echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > secret-file & curl.exe -sO http://localhost:8080/jnlpJars/agent.jar & java -jar agent.jar -jnlpUrl http://localhost:8080/computer/by%20connecting%20to%20controller/jenkins-agent.jnlp -secret @secret-file -workDir "/home/ubuntu/demoworkdir"

As far as I understand the localhost:8080 will only work on the same machine?

I have tried running the command on the same machine on which the controller is running, it works. The local agent gets connected successfully. I can even run jobs on the local agent.


Solution

  • As far as I understand the localhost:8080 will only work on the same machine?

    Yes, that is correct! That will only work if ran from the same machine as the controller. That is what localhost points at, it points at the local machine the command is being ran on.

    You should be able to however switch out localhost with the IP address of your Jenkins controller to be able to connect to it remotely (assuming that the agent is able to connect to the controller on port 8080)