How to setup Jenkins slave machine step by step guide
Jenkins is an open-source automation server, it can be used as automating all kind of task such as building project, testing, deploying project. In software development, DevOps is a very important process nowadays and Jenkins is an essential tool to follow the processes. It is really imported to know how to install Jenkins and set up the Jenkins slave.
Before downloading the Jenkins you need to download and install Java JDK.
Step 1:
Download Jenkins: Jenkins can be downloaded from below link
Jenkins Download
It will download a "jenkins.war" file.
Step 2:
Copy the .war file in a folder. I am copying "jenkins.war" file in my D:/java/ folder.
Step 3:
Open up a terminal in the download directory and run below command
java -jar jenkins.war --httpPort=8080
Here "--httpPort=8080" is optional field. By default, Jenkins runs on 8080 port, but if you want to change the port number then you have to mention the port number as mentioned above.
Step 4:
Once you run the command, Jenkins server starts working and configuration setup starts.
Please find the configuration procedure to setup Jenkins master
Step 5:
Next, we need to setup Jenkins node from Jenkins master. Before creating Jenkins node we need to enable TCP port for JNLP agents. We can enable TCP port for JNLP agents from below steps
1. Click on Manage Jenkins
2. Click on Configure Global Security.
3. Click on the Random radio button beside "TCP port for JNLP agents".
Add a new node from Manage Jenkins -> Manage Nodes
We need to provide some information about the node. Once we click on the Manage Node link node page will open and we will see "New Node" link.
Steps for adding a new node.
1. Click on the New Node
2. Provide the node name
3.Click on the radio button Permanent agents
4. Click Ok
Now we need to provide below details for newly created node
Name: < Name of the Node e.g. slave 1>
Description: < Description of the project (This is an optional field)>
# of executors:
The maximum number of concurrent builds that Jenkins may perform on this agent.
The default value is 1.
Remote root directory: This is a mandatory field.
An agent needs to have a directory dedicated to Jenkins. Specify the path to this directory on the agent.
It is best to use an absolute path, such as /var/jenkins or c:\jenkins. This should be a path local to the
agent machine. There is no need for this path to be visible from the master.
e.g. c:\jenkins
Labels:
Labels (or tags) are used to group multiple agents into one logical group.
For example, if you have multiple Windows agents and you have a job that must run on Windows, then
you could configure all your Windows agents to have the label windows, and then tie that job to this
label.
This would ensure that your job runs on one of your Windows agents, but not on any agents without
this label.
Launch method
Controls how Jenkins starts this agent.
In my tutorial, I am using Launch agent Java Web Start.
I have created one slave with below configuration
Once we have created slave node we can see newly created slave node displayed under Build Executor Status section on Jenkins home page. But we can see that node as offline mode like below
How to start Jenkins slave machine
1. Open the Jenkins server from slave machine
Suppose Jenkins server running on 192.168.0.103 and Jenkins port is 8080 then you need to open Jenkins from another machine in the same network with 192.168.0.103.8080.
2. Provide user name and password.
3. Click on the Jenkins slave machine (In my case slave 1)
4. Click on the slave.jar hyper link, you will see slave.jar will be downloaded in slave machine. You just need to copy that jar file into you slave Jenkins directory. I have created Jenkins directory in my d:/jenkins folder.
5. Open command prompt or cmd and navigate to the folder where you paste or download the slave.jar
6. Copy the command mentioned in the node
java -jar
slave.jar -jnlpUrl http://localhost:8080/computer/slave1/slave-agent.jnlp -secret e15c60d05ca37d01d593abd6297d6e3f1bb3b9d91c3c97d9155262acea8c61d3 -workDir "d:\jenkins"
You just need to change the ip address. You need to provide master machine ip address where the jenkins server is running. In my case, my server running on 192.168.0.103 and post is 8080 , so command should be
java -jar <a href="http://192.168.0.103:8080/jnlpJars/slave.jar" style="box-sizing: border-box; color: #5c3566; word-wrap: break-word;">slave.jar</a> -jnlpUrl http://192.168.0.103:8080/computer/slave1/slave-agent.jnlp -secret e15c60d05ca37d01d593abd6297d6e3f1bb3b9d91c3c97d9155262acea8c61d3 -workDir "d:\jenkins"
7. Paste the command in command prompt. and hit enter
8 . Afer successfully executed the command Jenkins slave will be online.