Jenkins:启动远程VM并使其保持运行状态 [英] Jenkins: Start remote VM and keep it running

查看:99
本文介绍了Jenkins:启动远程VM并使其保持运行状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Jenkins在Jenkins从属服务器上启动虚拟机.然后,VM本身将充当Jenkins从机. 为此,即使在Jenkins作业终止后,我也需要启动VM并保持其运行.我尝试创建一个自由样式项目,该项目在从属服务器上运行批处理脚本,并检查VM是否正在运行:

I am trying to get Jenkins to start a virtual machine on a Jenkins slave. The VM itself will then act as a Jenkins slave. In order to do so I need to boot the VM and keep it running, even after the Jenkins job terminates. I have tried to create a freestyle project which runs a batch script on the slave and checks if the VM is running:

"C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" -T ws start "D:\VM\MyVM.vmx"

"C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" list

第二个命令向我显示VM实际上已经启动并正在运行,但是显然它又直接关闭了,因为我看不到与VM对应的节点处于联机状态.

The second command shows me that the VM is actually up and running, but apparently it directly shuts down again since I can't see the node that corresponds to the VM as online.

Jenkins Slave代理作为Windows服务安装在VM的主机上,并以域用户身份登录.

The Jenkins Slave agent is installed as a Windows service on the VM's host and logs in as a domain user.

如果我将第一个命令切换到

If I switch the first command to

"C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" -x "D:\VM\MyVM.vmx"

虚拟机启动,该节点连接到Jenkins.这是因为批处理脚本在此命令后以某种方式卡住并且不会终止,因此VM仍保持开机状态.但是,如果我使用Jenkins服务使用的同一用户登录主机,则无法看到虚拟机正在运行.

the VM powers on, the node gets connected to Jenkins. This is because somehow the batch script gets stuck after this command and does not terminate, so the VM remains powered on. However, if I log on the host with the same user the Jenkins service uses, I cannot see the VM running.

具有讽刺意味的是,实际上,我可以通过使用批处理命令创建一个项目来关闭我在Jenkins主机上本地启动的任何虚拟机的电源

Ironically, I can in fact power OFF any virtual machine that I have started locally on the host from Jenkins by creating a project with the batch command

"C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" -T ws stop "D:\VM\MyVM.vmx" soft

因此,总结一下: 我想创建一个可以启动VM的Jenkins作业,以便可以将其用作从属代理.即使完成作业后,VM也必须保持开机状态,我将根据需要使用其他作业将其关闭. 但是,只有关闭作业才能按预期工作.

So, to summarize: I want to create a Jenkins job that powers on a VM so I can use it as a slave agent. The VM has to remain powered on even after the job is done, I will shut it down with a different job as needed. But only the shutdown job is working as intended.

推荐答案

今天玩完虚拟机和Jenkins之后,我了解到,如果Jenkins从站不是作为Windows服务运行而是通过Java Webstart应用程序启动的,则vmrun可以完美运行.

After playing around with VMs and Jenkins today I learned that vmrun works perfectly if the Jenkins slave does not run as a Windows service but is launched via the Java Webstart application.

此外,可以通过更改BUILD_ID env防止进程被杀死.变量,因为Jenkins使用此变量来跟踪构建启动的过程.因此,通过在生成进程之前更改BUILD_ID的值,它们不会在作业完成后被杀死.

Besides, one can prevent processes from getting killed by altering the BUILD_ID env. variable since Jenkins is using this variable to track the processes the build launched. So by changing the value of BUILD_ID before spawning processes they won't get killed after the Job finishes.

这篇关于Jenkins:启动远程VM并使其保持运行状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆