How To Setup Master Slave In Jenkins

Create another server and install java in it using the command i.e mentioned in installing jenkins on ubuntu, we will consider this server as a slave server

sudo apt install openjdk-8-jdk -y

Setup Jenkins Slave

Create the user and add user to wheel group.

useradd jenkins-slave-01

Create SSH Keys

sudo su - jenkins-slave-01
ssh-keygen -t rsa -N "" -f /home/jenkins-slave-01/.ssh/id_rsa

The private and public keys are created at these locations.

`/home/jenkins-slave-01/.ssh/id_rsa` and `/home/jenkins-slave-01/.ssh/`

cd .ssh
cat > authorized_keys
chmod 700 authorized_keys

Configuration on Master

  • Copy public key[] of slave node to Node’s known_hosts file of Master.
  • mkdir -p /var/lib/jenkins/.ssh
    cd /var/lib/jenkins/.ssh
    ssh-keyscan -H SLAVE-NODE-IP-OR-HOSTNAME >>/var/lib/jenkins/.ssh/known_hosts

    ssh-keyscan -H 172.31.*.* >>/var/lib/jenkins/.ssh/known_hosts

    chown jenkins:jenkins known_hosts
    chmod 700 known_hosts

    Configure the Slave using Manage Jenkins

  • Configure the node as shown here,go to Manage Jenkins > Manage Nodes > New Node
  • manage jenkins & node
    Test Jenkins Jobs

    1. Create “new item”

    2. Enter an item name – My-First-Project

    a) Chose Freestyle project

    3. Under General Section

    a) Choose Restrict where this project can be run

  • Update your jenkins slave label Java
  • 4. Under Build section Execute shell


    5. Save your job

    6. Build job

    7. Check “console output”

    console output

Subscribe Now