Controlling VirtualBox VM with VBoxManage from TeamCity
I'm having problems controlling my virtual machine using the VBoxManage tool when invoked from a TeamCity build step. In particular, I'm trying to attach a USB device to the VM before I run my unit tests. After the unit tests, I also want to clean up by detaching the USB device from the VM.
Here are the commands that are failing:
VBoxManage list vms <== to get a listing of the running VMs. This will return an empty string when run from TeamCity
VBoxManage list usbhost <== to get a list of USB devices and their corresponding UUIDs
VBoxManage controlvm <VM Name> usbattach <some UUID> <== to attach the USB device to the VM
VBoxManage controlvm <VM Name> usbdetach <some UUID> <== to detach the USB device from the VM
Note that when TeamCity runs my command line build steps, it is running as the "nt authority\system" account.
Initially, I would start the Virtual Machine using my normal login. To get the system user to see the VM, VBOX_USER_HOME environmental variable to point it to the correct location.
This cause the VBoxManage tools to fail to find my virtual machines that were created under a different user.
Next I tried starting the Virtual Machine from the system account and have verified that the above VBoxManage commands work fine when run from a local system account shell. Unfortunately, the TeamCity build steps still failed.
I use the "whoami /all" command to look at all the permissions. Unfortunately, they are the same when invoked from TeamCity or from the local system account shell.
So, what is different between a "nt authority\system" shell launched from TeamCity compared to one launched with "PSEXEC -i -s -d CMD"?
Has anyone been able to use VBoxManager in a TeamCity build step? If so, I'd love to learn the "trick".
Note in frustration, I tried numerous ways to have the TeamCity build step "become" a different user. Although these did become a different user, they couldn't successfully use the VBoxManage commands. These approaches were:
- Use "runas"
- Use ssh to log back into the same machine
Thanks in advance!
- Jeff
Please sign in to leave a comment.
Hi Jeff,
Are you running teamcity agent as service? Could you please try to run agent manually via console?
To whoever comes across this posting. Alina's hint works! To use
VBoxManage from TeamCity, you need to run the build agent as a console. I do it with the following steps:
At least for me, my TeamCity build steps that do VBoxManage operations now work! If the agent is running as a "service", then many of the VBoxManage operations will fail.
I hope this helps others in the future.
Regards, Jeff