Jenkins Master Slave Configuration. (Ubuntu instance as a slave)

 Connect Ubuntu server as a Slave - Using Private Key



Hi everyone ! In my Internship project, I had to configure a Ubuntu Instance as a Slave/Node to run a Jenkins job. That Instance runs in a AWS server. In this blog I'll show in simple steps how I configured that instance as a slave in Jenkins.

I needed the following details about the instance.

   IP of the Ubuntu instance.
   User name (which is configured in the instance)
   My private key 

Step 1 : 

Go to Manage Jenkins from the left menu

Step 2 :

Select Manage Nodes


Step 3 :

Select New Node and enter the node details.        

 1. Name Name of the node. This name will get displayed in the main view, under nodes section.

 2. Description - A Description. Better to include details about RAM, CPU storage etc.

 3. # of executors - The maximum number of concurrent builds that Jenkins may perform in this node.

 4. Remote root directory - Specify a directory in the agent node. (Note that the workspace will get created inside this directory in the slave node.) Best to give the absolute path.

 5. Labels -  Needed when assigning jobs to the node. You will have to mention this label in the job configuration to get your work done in this node. Can use 1 or more label names (Multiple labels must be separated by a space)

 6. Launch method - Select Launch agents via SSH


   7. Host - Enter the node's IP.

   8. Credentials - Click on Add to create new credentials and select Jenkins.

                                     i. Kind - Choose SSH Username with private key.                        

                                        

                                    ii. ID - Add something unique to identify the credentials.

                                    iii. Description - A description about the credentials.                                     

                                    iv. Username - Enter the user which is configured in the Slave node here.

                                    v. Private Key - Enter your private key (copy paste)    

                        Finally the credentials will look something like this.             

    
            8. Click Add.                      

Now choose the newly created credentials from the drop down menu.          


        Below those settings, You can add some other details under Node Properties.

        For example - You can set up the Environment details as below.(such as bin locations of several tools etc)


        Also You can select and add Tool Locations. (Maven path, JDK,node path etc.)

Step 4 :

Finally Click Save and you will see the Created Node. It launches the agent automatically.

        

If there are any errors you will see a cross near the agent icon with a Launch Agent Button.             

   You can find the error by clicking on Launch agent button. Please recheck the IP , Private key to avoid such errors.

When the errors are fixed you will see the below line in the end of process.

Step 5 : 

Test the node by creating a Jenkins job.

Go to Jenkins main page, 
        1. Select New Item
        2. Enter a project name and choose Free style project.
        
        3. In the project configuration, Under General click on Restrict where the project can be run and enter the label of the configured node.
        


4. Under Build section, Add a build step - Choose Execute Shell and type any commands that will make sure if the job is running in the slave node. for ex - 
        lsb_release -a    -To check the Ubuntu version.
            
        id  -To check the current user. (It should return the user which you specified in the node settings)
            

Step 6 :         

   Click Apply and Save.

            Build the job and check if the build succeeds. 
            
           In the console Output, I got the Ubuntu instance details and the user 'ubuntu' which I specified in the node settings.

    

        

        










Comments