Restore snapshot before build in jenkins using virtualbox plugin

こ雲淡風輕ζ 提交于 2019-12-11 11:17:31

问题


I'm using VirtualBox plugin on jenkins, to launch different builds retrieving sources from Git. I would like the environment on each VM to be clean by restoring a snapshot before starting them for a build.

I tried several things as https://wiki.jenkins-ci.org/display/JENKINS/Slave+Setup+Plugin. Finally I don't think it it's a good solution as it is called after the git repository being clone... But I also tried to launch the slave "via the execution of a command on master", that takes as parameter the name of the vm and calls this script:

VBoxManage registervm "C:\Users\mfauvet\VirtualBox VMs\%1\%1.vbox
VBoxManage controlvm %1 poweroff
VBoxManage snapshot %1 restore SetEnvironment
VBoxManage startvm %1
ssh 192.168.120.1 -p 1310

But I have the following error:

C:\Program Files (x86)\Jenkins>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" registervm "C:\Users\mfauvet\VirtualBox VMs\Jenkins-Ubuntu13.10\Jenkins-Ubuntu13.10.vbox" 
VBoxManage.exe: error: Trying to open a VM config 'C:\Users\mfauvet\VirtualBox VMs\Jenkins-Ubuntu13.10\Jenkins-Ubuntu13.10.vbox' which has the same UUID as an existing virtual machine
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component Machine, interface IMachine, callee IUnknown
VBoxManage.exe: error: Context: "OpenMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())" at line 88 of file VBoxManageMisc.cpp

C:\Program Files (x86)\Jenkins>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm Jenkins-Ubuntu13.10 poweroff 
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

C:\Program Files (x86)\Jenkins>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" snapshot Jenkins-Ubuntu13.10 restore SetEnvironment 
0%...10%...20%...30%...40%...50%...
Progress object failure: RPC_S_SERVER_UNAVAILABLE 0x800706BA
Restoring snapshot 7f7cc1a3-7128-426a-bf74-9ffb0b3fbca8

C:\Program Files (x86)\Jenkins>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm Jenkins-Ubuntu13.10 
VBoxManage.exe: error: Could not find a registered machine named 'Jenkins-Ubuntu13.10'
VBoxManage.exe: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee IUnknown
VBoxManage.exe: error: Context: "FindMachine(Bstr(pszVM).raw(), machine.asOutParam())" at line 575 of file VBoxManageMisc.cpp

Does someone know how I could solve this ? Or is there a better way to restore a snapshot on my vm before launching them via Jenkins ? Thanks for reading


回答1:


I got this working, admittedly with VMWare.

Steps I took

  1. add swarm plugin to master
  2. Setup virtual machine and add swarm client
  3. make sure client connects - will be in nodes in master
  4. take snapshot with the slave client running (or initiate it on startup)
  5. create a job on master which runs on your swarm slave
  6. add multijob plugin to master create multijob project with normal steps to revert the VM
  7. add a multijob phase
  8. add the swarm slave job into the multijob phase

When running the job, the swarm slave job will wait for the VM to start before submitting jobs to it



来源:https://stackoverflow.com/questions/22565180/restore-snapshot-before-build-in-jenkins-using-virtualbox-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!