I have a VirtualBox Jenkins slave. I start it manually every time it goes down (e.g. after doing reboot to the PC).
Is there a way to make Jenkins start it automatically?
I have a VirtualBox Jenkins slave. I start it manually every time it goes down (e.g. after doing reboot to the PC).
Is there a way to make Jenkins start it automatically?
I have a Windows host that should run an Ubuntu 14.04 virtual machine Jenkins slave.
Pre-requirements: you should have a VM slave defined in Jenkins (http://YOUR-JENKINS-URL/computer/)
This is how I solved it:
1) Setup Ubuntu VM to automatically start a service on boot that runs a script to start Jenkins slave:
Use upstart to run the script: create a the file /etc/init/jenkins-slave.conf
description "A job to start a Jenkins slave"
author "Your Name"
start on runlevel [2345]
exec echo Starting Jenkins slave at `date` >> /var/log/jenkins-slave-job.log
exec /jenkins/run.sh
The /jenkins/run.sh:
cd $(dirname $0)
java -jar slave.jar -jnlpUrl
http://YOUR-JENKINS-URL/computer/NAME-OF-NODE/slave-agent.jnlp -secret 51d080f68b3d2552c977840aa8a01bb371a1b3e8b3326f36fadb497e597185ce
The /Jenkins folder should contain slave.jar file downloaded from Jenkins node page.
The 2 last lines in the run.sh file should be taken from the Jenkins node page.
2) Setup Windows to start the VM on startup:
Create a Windows shourtcut with the following value in the "Target:"
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm "UbuntuVBox"
Where UbuntuVBox should be replaced with the name of your VM
Put the shortcut under "Startup" folder in the Windows start menu
To conclude:
After doing the above steps - if you reboot the Windows host, it should run the shortcut, that will run the VM. The VM will run the service "Jenkins-slave" and your Jenkins slave should be up and running.
Short answer:
Yes, we can do it.
Just add VitrualBox as a service in your PC, and add Jenkins Slave as an service in that VitrualBox VM.
Long answer:
In fact, we are talking about two things here:
Or , in another word , we are talking one thing:
But the detail operations related to the OS you are using. (For windows, this tool may help: https://nssm.cc/)
There is a VirtualBox Plugin that:
starts VMs automatically when needed
stops VMs when no longer needed
It requires VirtualBox web service (vboxwebsrv) to control VMs (see e.g. chapter 9.12 of the VirtualBox documentation to get it running).