Integrating Jenkins with Oracle VirtualBox VM

Problem Statement:

We know that VirtualBox plugin is available in jenkins which enables jenkins connectivity with oracle  virtualbox.However,as of today, this is officilally supporting virtualbox <=v4.3 only.Latest virtualbox versions such as 5.2 are not supported by this plugin.Hence we need other generic mechanism to solve this problem.

Solution:

Below steps are generic and are independent of virtualbox versions.
 
NOTE:Below commands are tested with 'Windows7 host' and 'CentOS linux7 guest'.The commands used below might change slightly based on virtualbox version installed.
 
Environment:Consider below setup
Host:MCPRCH01-->This is a windows7 host machine on which Virtualbox software is installed.
Guest:EDGE-Server-->This is a virtual appliance bundled with 'CentOS linux7' that runs inside Host machine.
Jenkins:Jenkins is installed on this machine.
 
Step1:Create a HOST node in jenkins and start the HOST jenkins slave.
Step2:Create a job(Job1) in jenkins which will run on HOST.
Step3:Run below commands from above jenkins job.This will import ova file and start the guest server.
 
cd C:\Program Files\Oracle\VirtualBox  [VirtualBox installation directory]
vboxmanage unregistervm EDGE-server   [If server with same name already exists and want to delete it]
vboxmanage import C:\EDGE-server-9.8.8-1-duerr.ova  [Imports ova file to Virtualbox]
VBoxManage modifyvm EDGE-server --natpf1 "SSHForwardRule,TCP,,22,,22"   [SSH port forward is set from HOST(windows) to GUEST(linux)]
VBoxHeadless -s EDGE-server  [Starts the GUEST]
 
Step4:Now create one more node in jenkins and name it as EDGEServer.Set,
Launch method = 'Launch slave agents via SSH'
Host = MCPRCH01(a widnows hostname)
Credentails = Provide login details of CentOS EDGE-server
Host Key Verification Strategy = Non verifying Verification Strategy
 
Step5:Now start the EDGEServer slave from jenkins.We should see 'Agent successfully connected and online'.
 
Step6:Create a job(Job2) in jenkins which does actual stuff and point it to run on EDGEServer slave.
 
Job1 and Job2 together makes the entire process of 'importing ova files,starting guest server,configuring jenkins slave for guest' automatic without manual intervention.