Jenkins unable to start Oracle VirtualBox - windows

I have a batch file I have made that runs Oracle's VirtualBox in the headless mode. When I run the command in the windows command prompt it works fine without any errors.
C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "Ubuntu" --type headless
Waiting for VM "Ubuntu" to power on...
VM "Ubuntu" has been successfully started.
C:\Program Files\Oracle\VirtualBox>
However, when I call the batch script that has the same command via Jenkins I get the following error:
C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "Ubuntu" --type headless
VBoxManage.exe: error: Failed to create the VirtualBox object!
VBoxManage.exe: error: The object is not ready
VBoxManage.exe: error: Details: code E_ACCESSDENIED (0x80070005), component VirtualBoxClientWrap, interface IVirtualBoxClient
Every VirtualBox command called from Jenkins gives the same error.
C:\Program Files\Oracle\VirtualBox>VBoxManage sharedfolder add "Ubuntu" --name BranchRepo --hostpath "A PATH" --automount
VBoxManage.exe: error: Failed to create the VirtualBox object!
VBoxManage.exe: error: The object is not ready
VBoxManage.exe: error: Details: code E_ACCESSDENIED (0x80070005), component VirtualBoxClientWrap, interface IVirtualBoxClien
Any suggestions as to how to fix this issue? Is there some particular way to grant Jenkins the required permissions?

It seems that that the user with which it runs has incorrect permissions.
You can try and run Jenkins' service as a separate local admin user.
Start => 'services' => Scroll to the Jenkins service => right click => properties => "log on" => "this account" => specify a local admin account.
Edit:
Editing the "Registry Editor" worked

Related

Failed to create the VirtualBox object

I was trying to login into the already existing vm using vagrant in bash. But it says failed to start or it's not running.
This is a already existing vm in the local.
I tried
$vagrant global-status -> to get the vm id.
then,
$vagrant up <id> ->to start the vm.
Got the following error,
There was an error while executing VBoxManage, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["showvminfo", "cd2ec772-3e94-476f-a0d9-59c3d2768fb5"]
Stderr: VBoxManage.exe: error: Failed to create the VirtualBox object!
VBoxManage.exe: error: Code REGDB_E_CLASSNOTREG (0x80040154) - Class not registered (extended info not available)
VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running or failed to start.

OpenStack training-labs - VBoxManage.exe: error: Invalid machine group

I am trying to install OpenStack instance into VirtualBox VMs as on https://wiki.openstack.org/wiki/Documentation/training-labs#Building_the_cluster
after ./osbash.sh -w cluster I get error
VBoxManage.exe: error: Invalid machine group 'C:/Program Files/Git/labs'
Yes, C:/Program Files/Git is location of git-bash.exe that is actual Git-Windows Bash, but how to make osbash.sh proceed with correct machine group name?
The scripts are stable Mitaka from http://docs.openstack.org/training_labs/ for Windows
http://tarballs.openstack.org/training-labs/dist/labs-stable-mitaka.zip
Paul#aspire MINGW64 /d/Workspaces/OpenStack/labs-stable-mitaka/labs/osbash
$ ./osbash.sh -b cluster
Base disk: base-ssh-mitaka-ubuntu-14.04-server-amd64
Distribution name: ubuntu
Virtualization provider: virtualbox
Creating Windows batch scripts: no
Creating cluster on this machine: yes
VM access method: ssh
GUI type: headless
2016年09月20日 18:09:36 osbash starting
Creating basedisk.
2016年09月20日 18:09:36 osbash vm_install starts.
Asked to delete VM "base" (not found)
Creating VM "base"
VBoxManage.exe: error: Invalid machine group 'C:/Program Files/Git/labs'
VBoxManage.exe: error: Details: code E_INVALIDARG (0x80070057), component VirtualBoxWrap, interface IVirtualBox, callee IUnknown
VBoxManage.exe: error: Context: "ComposeMachineFilename(bstrName.raw(), bstrPrimaryGroup.raw(), createFlags.raw(), bstrBaseFolder.raw(), bstrSettingsFile.asOutParam())" at line 264 of file VBoxManageMisc.cpp
FAILURE: VBoxManage: createvm --name base --register --ostype Ubuntu_64 --groups /labs
P.S. The same error when trying the latest master from git://git.openstack.org/openstack/training-labs.git
Raised bug https://bugs.launchpad.net/labs/+bug/1625562
The documentation may have mislead you. You don't need a POSIX environment to build the cluster on Windows and (as you found out) using the bash scripts does not work on Windows.
All you need is a VirtualBox installation and the content of the zip file you downloaded. There is no need to add VBoxManage to the Path, the scripts should find the executable anyway.
The zip file you downloaded contains the Windows batch files that build the cluster on Windows in the wbatch directory. Just double-click them: 1) create_hostnet 2) create_base 3) create_ubuntu_cluster_node
That's all. The scripts will set up the VMs, download the Ubuntu ISO image and build the OpenStack cluster.

VAGRANT UP not working when executed via BAMBOO

I am trying to work with Vagrant and Bamboo together. I created custom box which I put on a web server from which it is getting downloaded when doing vagrant up. When I do it manually on the computer everything goes as expected.
When I try this via Bamboo however, the folder for local box in c:\Windows\System32\config\systemprofile\.vagrant.d\boxes is not created and subsequently fails as vagrant is not able to do import.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'http://127.0.0.1:8000/k.box'...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["import", "-n", "C:/Windows/System32/config/systemprofile/.vagrant.d/boxes/http-VAGRANTCOLON--VAGRANTSLASH--VAGRANTSLASH-127.0.0.1-VAGRANTCOLON-8000-VAGRANTSLASH-k.box/0/virtualbox/box.ovf"]
Stderr: 0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage.exe: error: Appliance read failed
VBoxManage.exe: error: Could not read OVF file 'box.ovf' (VERR_PATH_NOT_FOUND)
VBoxManage.exe: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component ApplianceWrap, interface IAppliance
VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleImportAppliance(struct HandlerArg *)" at line 307 of file VBoxManageAppliance.cpp
Did any of you encountered similar problem?
Thank you.
After some investigation I found the reason for this. The problem is that by default .vagrant.d folder is created in C:\Windows\SysWOW64\config\systemprofile when the vagrant is run via Bamboo. This is the folder where the boxes are stored after download.
The PROFILEUSER environment variable is set to C:\Windows\System32\config\systemprofilefor SYSTEM user. Subsequently after downloading the box it went to look for it into .vagrant.d folder inside PROFILEUSER folder instead of the one that really stored the box.
This problem was solved by setting VAGRANT_HOME environment variable to C:\Windows\SysWOW64\config\systemprofile\.vagrant.d. After this, vagrant looks into correct folder for stored boxes.

Restoring Laravel's Homestead after critical error

I'm using Homestead via Vagrant for my Laravel environment. When I ran vagrant up today, there was a critical error saying that the box is inaccessible.
One of the instructions that I found on the web suggested unregistering the VM by using its machine uuid, which I did:
> VBoxManage.exe unregistervm [uuid]
After unregistering the status of Homestead box changed from inaccessible to not created.
Next step was to register the box, which I do like this:
> VBoxManage.exe registervm "C:\Users\Rhino\VirtualBox VMs\homestead\box-disk1.vmdk"
However the command above throws the following error:
VBoxManage.exe: error: Start tag expected, '<' not found.
VBoxManage.exe: error: Location: 'C:\Users\Rhino\VirtualBox VMs\homestead\box-disk1.vmdk', line 1 (0), column 1.
What am I doing wrong?
OK, I figured it out. There was probably a step missing in the guide I found - creation. All the steps again:
(1)Unregister the box with machine uuid. The uuid can be found e.g. in the .vbox-prev file in your homestead virtual machine folder. Run this when you retrieve the uuid:
C:\Program Files\Oracle\VirtualBox> VBoxManage.exe unregistervm [uuid]
(2)Create the box with --register flag:
C:\Program Files\Oracle\VirtualBox> VBoxManage.exe createvm --name "C:\Users\Rhino\VirtualBox VMs\homestead\box-disk1.vmdk" --register
(3)Delete the folder in which your homestead vm is kept (I guess it's by default created in VirtualBox VMs folder)
(4)Run vagrant up

How to create a jenkins job in order to perform VBoxManage operations on virtual images?

I want to setup a jenkins job in order to e.g. clone a virtual image. The (working) command line is e.g.
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonevm UbuntuTest --name TestNeu --register
However, the same command line executed in jenkins as window batch script does not work, it gives an error
VBoxManage.exe: error: Could not find a registered machine named 'UbuntuTest'
VBoxManage.exe: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee IUnknown
VBoxManage.exe: error: Context: "FindMachine(Bstr(pszSrcName).raw(), srcMachine.asOutParam())" at line 434 of file VBoxManageMisc.cpp
I only can suppose this jenkins script runs as a different user and does not know of the available images located in C:\Users\alex\VirtualBox VMs.
How to fix this problem?
Addendum:
Running this as a different user does not seem to work or is impossible: link
You need to define your Jenkins slave process to run as the desired user.
First install Jenkins slave as a Windows service , then go the service properties and in the 'Log On' tab change it from the default 'Local System Account' to "This Account:" - enter your account name (alex) and password.
Don't forget to restart the service.

Resources