Skip to content

Latest commit

 

History

History
167 lines (130 loc) · 4.63 KB

File metadata and controls

167 lines (130 loc) · 4.63 KB

Virtual Machine agent

To set up an agent on a VM, we first need to have the VM on same network. For this, I created a VM using Oracle Virtualbox and installed Ubuntu on it.

Steps to Create VM:

  1. Download and install virtualbox > https://www.virtualbox.org/wiki/Downloads
  2. Create a new VM and install ubuntu. Link

Setps to Configure Network:

  1. Open Oracle virtualbox manager.
  2. Select the VM and open settings.
  3. Go to network.
  4. Replace NAT adapder in Adapter 1 with Bridge Adapter.

And we are good to launch the VM.

One time Installation on VM:

sudo apt update
sudo apt-get install openssh-server

Add new agent on Jenkins

  1. Go to Manage Jenkins. Go to Manage Nodes and Clouds.
  2. Go to New Node. Enter Node name. Mark as Permanent agent and click Ok.

  1. Upadate No. of executors to 2,3 whatever. You can keep it 1 as well. This controls how many executors are allowed on a node to run in parallel.

  2. Update remote root directory

/home/<user>

In my case, it is /user/kamal

  1. Update labels. Set it to ubuntuNode1

  2. Select Usage as : "Only Build jobs with label expressions matching this node". This restricts the executions meant for this node to run on this node only.

  3. Select Launch method as "Launch agents via SSH". In case you do not see this opetion in dorpdown, you need to install SSH plugins on Jenkins.

  1. Get the ip of ubuntu. Use this command on ubuntu terminal(Virtual machine/node).
ifconfig

The host should be able to ping VM for communication. We have changed adapted to Bridge to make this possible. To check this, you can run the command from host:

ping 192.168.29.119

where 192.168.29.119 is VM ip address in our case.

  1. Enter VM's IP in "Host ip". In our case it is 192.168.29.119

  2. Add credentials of VM in creadential manager(if not added already). Select that from dropdown for authentication.

  3. Enter Host Key verification strategy as "Non verifying verification strategy"

  4. Select Availability as "Bring this agent online when in demand and take offline when idle.". You can choose as per your requirement. This option enables node to be active only when needed.

  1. Save.

  2. Now run the pipeline using pipelin script. And it should work.

pipeline {
    agent {
        label 'ubuntuNode1'
    }
    stages {
        stage('pre -build') {
            steps {
                sh 'echo Pre-build'
            }
        }
        stage('build') {
            steps {
                sh 'echo Build in progress.'
            }
        }
        stage('Unit tests') {
            steps {
                sh 'echo Running unit tests'
            }
        }
        stage('deploy') {
            steps {
                sh 'echo Deploying build'
            }
        }
        stage('Regression tests') {
            steps {
                parallel(
                    chrome : {
                        sh 'echo Running E2E tests on chrome'
                    },
                    firefox : {
                        sh 'echo Running E2E tests on chrome'
                    },
                    safari : {
                        sh 'echo Running E2E tests on chrome'
                    }
                )
                
            }
        }
        stage('Release to prod') {
            steps {
                sh 'echo Releasing to prod'
            }
        }
    }
 post {
        always {
            echo 'Cleanup after everything!'
        }
    }
}
  1. Now if we use JENKINSFILE5 from github repo to build the pipeline, it may fail.
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE

For this, you need to Configure the Node again. And towards the Bottom, you'll find Node Properties. Check Tool Locations. Select Git default and set path as "/usr/bin/git"

Now it should work from JENKINSFILE as well.