How to create an agent in Linux from console

Issue

How to create an agent in Linux from console

Environment

Resolution

For adding a node as an agent to Jenkins controller using the console, follow following steps.

Step 1: On Jenkins controller go to Manage Jenkins > Manage Nodes.

New node link

Step 2: Select New Node and enter node name.

Step 3: select Permanent Agent -> Press OK.

Node name

Step 4: On the next page, fill in the following fields:

Set a number of executors (one or more) as needed. Default is 1.

Set a Remote FS Root, a home directory for the controller on the agent machine, e.g., “/opt/jenkins/”

Set Usage to “Use this node as much as possible”.

Choose Launch method as “Launch agent by connecting it to the controller” (formerly known as “master”, also known as “Launch agent via Java Web Start” before 2.176.1).

Set Availability, –> Keep this agent online as much as possible.

Press Save.

Configure job for agent

Step 5: Now for connecting to agent to the controller by

Open a browser on the agent machine and go to the Jenkins controller URL (http://YourJenkinsController:8080).

Go to Manage Jenkins > Manage Nodes, click on the newly created agent machine.

Run from agent command line. Login to agent node -> download the agent.jar file from Jenkins controller UI to agent machine then while executing the command, please specify download path of agent.jar file.

Agent not connected
On your console:

nohup java -jar /opt/jenkins/agent.jar -jnlpUrl http://YourJenkinscontroller:8080/computer/NameOfYourSlave/slave-agent.jnlp -jnlpCredentials userJenkinscontroller:passwordJenkinscontroller &

Now agent node will be in Connected state.

Agent connected

We recommend you choose connecting agent with ssh in linux servers How to connect to remote SSH Agents

References

Have more questions?

1 Comments

  • 0
    Avatar
    mark.kenneally Kenneally

    Using -jnlpCredentials userJenkinsMaster:passwordJenkinsMaster means that the Jenkins master password is available to any user who can run a job with the line "ps -aef" on the agent.

    We have used this format:

    curl -O -u userJenkinsMaster:passwordJenkinsMaster http://YourJenkinsMaster:8080/computer/NameOfYourSlave/slave-agent.jnlp
    export JENKINS_SECRET=$(grep -E -o "[a-z0-9]{64}" slave-agent.jnlp)
    nohup java -jar /opt/jenkins/slave.jar -jnlpUrl http://YourJenkinsMaster:8080/computer/NameOfYourSlave/slave-agent.jnlp -secret $JENKINS_SECRET &
    Edited by mark.kenneally Kenneally
Please sign in to leave a comment.