-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
I wondered if I can use the vSphere plugin to manage a standalone ESXi server, so it would provide clones of a pre-built system (as a template) as Jenkins workers. Or at least one discardable worker to run tests from a prepared pristine environment, that for my purposes could be as well the same VM reverted back to snapshot after each run, or a clone brought up and destroyed.
I looked at the vagrant plugin and scripted cloud plugin as other ways to achieve that, but they seem too aged. While vagrant as a toolkit apparently has its own plugins that let it use ESXi over SSH flexibly, the vagrant Jenkins plugin is rather dated and not even a cloud provider. The scripted cloud lets me use whatever scripts to start and stop... something... no bindings to labels etc.
So far it seems like my best shot would be to extend the vSphere plugin itself, and fall back to cloning via SSH access to ESXi which is widely documented on the Internet. It seems that for basic read-only needs of the Cloud provider setup page (Connection testing, Login, Checking if template config is sane) the existing REST API suffices. But when I ask the VM to appear, Jenkins log is peppered with these attempts every 10 seconds:
Dec 13, 2020 7:04:02 PM INFO org.jenkinsci.plugins.vSphereCloud InternalLog STARTING VSPHERE CLOUD Dec 13, 2020 7:04:52 PM INFO org.jenkinsci.plugins.vSphereCloud InternalLog STARTING VSPHERE CLOUD Dec 13, 2020 7:05:03 PM INFO hudson.slaves.SlaveComputer tryReconnect Attempting to reconnect master-worker Dec 13, 2020 7:05:59 PM INFO org.jenkinsci.plugins.vSphereCloud InternalLog STARTING VSPHERE CLOUD Dec 13, 2020 7:06:35 PM INFO org.jenkinsci.plugins.scripted_cloud.scriptedCloud InternalLog onStarted ..... Dec 13, 2020 7:06:49 PM INFO org.jenkinsci.plugins.vSphereCloud provision provision(testrunner-restapi-py,1): 0 existing slaves (=0 executors), templates available are [Template[prefix=worker-, provisioned=[], planned=[], unwanted={}, max=2147483647, fullness=0.000%]] Dec 13, 2020 7:06:49 PM INFO org.jenkinsci.plugins.vSphereCloud provision provision(testrunner-restapi-py,1): Provisioning 1 new =[worker-8v0tqvgiuolu8jk26y1vdfujk] Dec 13, 2020 7:06:49 PM INFO hudson.slaves.NodeProvisioner$StandardStrategyImpl apply Started provisioning worker-8v0tqvgiuolu8jk26y1vdfujk from vSphereCloud with 1 executors. Remaining excess workload: 0 Dec 13, 2020 7:06:50 PM WARNING org.jenkinsci.plugins.vSphereCloud$VSpherePlannedNode$1 call Failed to provision new slave worker-8v0tqvgiuolu8jk26y1vdfujk com.vmware.vim25.NotSupported at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:253) at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:363) at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:363) at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:363) at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:356) at com.vmware.vim25.ws.XmlGenDom.fromXML(XmlGenDom.java:233) at com.vmware.vim25.ws.XmlGenDom.fromXML(XmlGenDom.java:124) at com.vmware.vim25.ws.SoapClient.unMarshall(SoapClient.java:253) at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:96) at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:106) at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:98) at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:146) at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:167) at com.vmware.vim25.mo.Task.getTaskInfo(Task.java:51) Caused: org.jenkinsci.plugins.vsphere.tools.VSphereException: vSphere Error: Couldn't clone "jenkins-template-agent1". Clone task ended with status error. The operation is not supported on the object. at org.jenkinsci.plugins.vsphere.tools.VSphere.newVSphereException(VSphere.java:1151) at org.jenkinsci.plugins.vsphere.tools.VSphere.cloneOrDeployVm(VSphere.java:287) at org.jenkinsci.plugins.vSphereCloudSlaveTemplate.provision(vSphereCloudSlaveTemplate.java:428) at org.jenkinsci.plugins.vSphereCloudSlaveTemplate.provision(vSphereCloudSlaveTemplate.java:403) at org.jenkinsci.plugins.vSphereCloud$VSpherePlannedNode.provisionNewNode(vSphereCloud.java:534) at org.jenkinsci.plugins.vSphereCloud$VSpherePlannedNode.access$100(vSphereCloud.java:496) at org.jenkinsci.plugins.vSphereCloud$VSpherePlannedNode$1.call(vSphereCloud.java:510) at org.jenkinsci.plugins.vSphereCloud$VSpherePlannedNode$1.call(vSphereCloud.java:506) at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46) at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Dec 13, 2020 7:06:50 PM INFO org.jenkinsci.plugins.vsphere.tools.CloudProvisioningState logStateChange Marking worker-8v0tqvgiuolu8jk26y1vdfujk as failed
The ESXi server similarly logs attempts by root to "Clone VM" which "Failed - The operation is not supported on the object." (quite an interceptable string for the fallback mode someplace in https://github.com/jenkinsci/vsphere-cloud-plugin/blob/ed252da5121b96bf0c7d0467fc8400a76ff6b80c/src/main/java/org/jenkinsci/plugins/vsphere/tools/VSphere.java#L222 or whatever it calls, I suppose)
Clone VM
Key: haTask-1-vim.VirtualMachine.clone-3889797263
Description: Creates a clone of this virtual machine
Virtual machine: jenkins-template-agent1
State: Failed - The operation is not supported on the object.
Errors:
Currently this is expected and according to docs and disclaimers But I hope it can be fixed
As a side note, although the worker template announces its labels as a swarm agent (after it is up and running), I had to specify same labels in the Cloud provider config. Makes sense, but needed a bit of trial and error still.
Random links to SSH-based VM cloning: