Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-37008

Jenkins vSphere cloud plugin does not expose guest info to pipeline

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • vsphere-cloud-plugin
    • None
    • Jenkins 2.15, vSphere 6.0.0, vSphere Plugin 2.13

      It appears that the vSphere plugin action ExposeGuestInfo is intended to expose information to the Jenkins pipeline, however that information does not appear to be accessible.

      Sample pipeline:

      Jenkinsfile.groovy
      node() {
          vSphere buildStep: [$class: 'Clone', clone: 'cloned-vm', cluster: 'cluster', powerOn: true, resourcePool: 'resource-pool', sourceName: 'template'], serverName: 'vsphere_server'
          vSphere buildStep: [$class: 'ExposeGuestInfo', envVariablePrefix: 'VSPHERE', vm: 'cloned-vm'], serverName: 'vsphere_server'
          
          def test_vm_ip = env.VSPHERE_IpAddress
          echo "Created VM with IP: ${test_vm_ip}"
      }
      

      This results in the output:

      [Pipeline] vSphere
      [vSphere] 
      [vSphere] Performing vSphere build step: "Clone VM from VM or template"
      [vSphere] Attempting to use server configuration: "vsphere_server"
      [vSphere] Creating a shallow clone of "template" to "cloned-vm"
      [vSphere] Started cloning of VM. Please wait ...
      [vSphere] "cloned-vm" successfully cloned!
      [Pipeline] vSphere
      [vSphere] 
      [vSphere] Performing vSphere build step: "Expose Guest Info"
      [vSphere] Attempting to use server configuration: "vsphere_server"
      [vSphere] Exposing guest info for VM "cloned-vm" as environment variables
      [vSphere] Added environmental variable "VSPHERE_ToolsStatus" with a value of "toolsOk"
      [vSphere] Added environmental variable "VSPHERE_ToolsVersionStatus" with a value of "guestToolsCurrent"
      [vSphere] Added environmental variable "VSPHERE_ToolsVersionStatus2" with a value of "guestToolsCurrent"
      [vSphere] Added environmental variable "VSPHERE_ToolsRunningStatus" with a value of "guestToolsRunning"
      [vSphere] Skipped "GuestFamily" as it is a null value
      [vSphere] Skipped "Net" as it is of type class [Lcom.vmware.vim25.GuestNicInfo;
      [vSphere] Skipped "IpStack" as it is of type class [Lcom.vmware.vim25.GuestStackInfo;
      [vSphere] Skipped "Screen" as it is of type class com.vmware.vim25.GuestScreenInfo
      [vSphere] Added environmental variable "VSPHERE_GuestState" with a value of "running"
      [vSphere] Added environmental variable "VSPHERE_AppHeartbeatStatus" with a value of "appStatusGray"
      [vSphere] Skipped "GuestKernelCrashed" as it is a null value
      [vSphere] Added environmental variable "VSPHERE_AppState" with a value of "none"
      [vSphere] Added environmental variable "VSPHERE_GuestOperationsReady" with a value of "true"
      [vSphere] Added environmental variable "VSPHERE_InteractiveGuestOperationsReady" with a value of "false"
      [vSphere] Added environmental variable "VSPHERE_GuestStateChangeSupported" with a value of "true"
      [vSphere] Skipped "GenerationInfo" as it is of type class [Lcom.vmware.vim25.GuestInfoNamespaceGenerationInfo;
      [vSphere] Added environmental variable "VSPHERE_GuestFullName" with a value of ""
      [vSphere] Added environmental variable "VSPHERE_ToolsVersion" with a value of "10246"
      [vSphere] Skipped "Disk" as it is of type class [Lcom.vmware.vim25.GuestDiskInfo;
      [vSphere] Added environmental variable "VSPHERE_IpAddress" with a value of "10.81.92.222"
      [vSphere] Skipped "GuestId" as it is a null value
      [vSphere] Added environmental variable "VSPHERE_HostName" with a value of ""
      [vSphere] Successfully exposed guest info for VM "cloned-vm"
      [Pipeline] echo
      Created VM with IP: null
      

      Exposing, at the very least, the IP of the VM is pretty crucial component of using vSphere VMs in a pipeline.

          [JENKINS-37008] Jenkins vSphere cloud plugin does not expose guest info to pipeline

          Aleix Colla added a comment -

          If you only need the IP you can do the following:

          • def ip = vSphere buildStep: [$class: 'ExposeGuestInfo', envVariablePrefix: 'VSPHERE', vm: 'cloned-vm'], serverName: 'vsphere_server'
          • print ip

          The exposeGuestInfo buildStep returns a string with the IP

          Aleix Colla added a comment - If you only need the IP you can do the following: def ip = vSphere buildStep: [$class: 'ExposeGuestInfo', envVariablePrefix: 'VSPHERE', vm: 'cloned-vm'] , serverName: 'vsphere_server' print ip The exposeGuestInfo buildStep returns a string with the IP

          Scott Miller added a comment -

          Thank you, that's very helpful. I also need access to the GuestFamily value.

          Scott Miller added a comment - Thank you, that's very helpful. I also need access to the GuestFamily value.

          I've tried just about every combination I can think of to get the hostname of the VM, including $VSPHERE_HostName, $env.VSPHERE_HostName, env.HostName, env.hostName, VSPHERE.hostName, VSPHERE.HostName, and many others.

                  ip = vSphere buildStep: [$class: 'ExposeGuestInfo', envVariablePrefix: 'VSPHERE', vm: vmName], serverName: "vSphere Server"

          Yes, it returns the IP, but I also want to get the VM's reported hostname, which is logged as such:
          [vSphere] Added environmental variable "VSPHERE_HostName" with a value of "feature-beta-testing"
          This seems like it should be available either via $VSPHERE_HostName, or $env.VSPHERE_HostName.  Both return null.

          Richard Meserve added a comment - I've tried just about every combination I can think of to get the hostname of the VM, including $VSPHERE_HostName, $env.VSPHERE_HostName, env.HostName, env.hostName, VSPHERE.hostName, VSPHERE.HostName, and many others.         ip = vSphere buildStep: [$class: 'ExposeGuestInfo', envVariablePrefix: 'VSPHERE', vm: vmName] , serverName: "vSphere Server" Yes, it returns the IP, but I also want to get the VM's reported hostname, which is logged as such: [vSphere] Added environmental variable "VSPHERE_HostName" with a value of "feature-beta-testing" This seems like it should be available either via $VSPHERE_HostName, or $env.VSPHERE_HostName.  Both return null.

          I confirm the issue. Meanwhile is it possible to parse the text output and extract the value from it?

          Sebastien Hensgen added a comment - I confirm the issue. Meanwhile is it possible to parse the text output and extract the value from it?

          vassil marjunits added a comment - - edited

          Same problem with vSphere PoweOn/Resume class.
          exposing  vSphere variables to jenkins environmental variable not working in pipeline. Jenkins ver. 2.107.2, vSphere Plugin 2.17

          Im using vSphere PoweOn/Resume to get IP aadress.

          #!/usr/bin/env groovy
          def vmDomainName = 'vm-test.ci.kit'
          node() {
              stage ('Build'){
                  vSphere buildStep: [$class: 'PowerOn', timeoutInSeconds: 180, vm: vmDomainName], serverName: 'testvcs'
                  def vm_ip = env.VSPHERE_IP
                  def build_id = env.BUILD_ID
                  echo "VM IP: ${vm_ip}"
                  echo "Build_id: ${build_id}"
              }    
          }

          Console Output:
          Started by user someuser
          Running in Durability level: MAX_SURVIVABILITY[Pipeline] nodeRunning on
          Jenkins
          in /var/lib/jenkins/workspace/PowerOnVmPipeline[Pipeline] {[Pipeline] stage[Pipeline] { (Build)[Pipeline] vSphere[vSphere]
          [vSphere] Performing vSphere build step: "Power-On/Resume VM"
          [vSphere] Attempting to use server configuration: "testvcs"
          [vSphere] Successfully retrieved IP for "vm-test.ci.kit" : 10.0.24.55
          [vSphere] Exposing 10.0.24.55 as environment variable VSPHERE_IP

          [Pipeline] echoVM IP: null
          [Pipeline] echoBuild_id: 14
          [Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS
           

          Custom log record:
          Apr 17, 2018 6:14:17 PM FINE org.jenkinsci.plugins.workflow.job.WorkflowRun
          PowerOnVmPipeline #13 in /var/lib/jenkins/jobs/PowerOnVmPipeline/builds/13: result is set to SUCCESS java.lang.Exception at org.jenkinsci.plugins.workflow.job.WorkflowRun.setResult(WorkflowRun.java:738) at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:747) at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$1100(WorkflowRun.java:142) at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:1094) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:1413) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$3.run(CpsThreadGroup.java:412) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:35) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 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)
          Apr 17, 2018 6:14:17 PM INFO org.jenkinsci.plugins.workflow.job.WorkflowRun finish
          PowerOnVmPipeline #13 completed: SUCCESS

           

          vassil marjunits added a comment - - edited Same problem with vSphere PoweOn/Resume class. exposing  vSphere variables to jenkins environmental variable not working in pipeline. Jenkins ver. 2.107.2, vSphere Plugin 2.17 Im using vSphere PoweOn/Resume to get IP aadress. #!/usr/bin/env groovy def vmDomainName = 'vm-test.ci.kit' node() {     stage ('Build'){         vSphere buildStep: [$class: 'PowerOn', timeoutInSeconds: 180, vm: vmDomainName] , serverName: 'testvcs'         def vm_ip = env.VSPHERE_IP         def build_id = env.BUILD_ID         echo "VM IP: ${vm_ip}"         echo "Build_id: ${build_id}"     }     } Console Output: Started by user someuser Running in Durability level: MAX_SURVIVABILITY [Pipeline] node Running on Jenkins in /var/lib/jenkins/workspace/PowerOnVmPipeline [Pipeline] { [Pipeline] stage [Pipeline] { (Build) [Pipeline] vSphere [vSphere] [vSphere] Performing vSphere build step: "Power-On/Resume VM" [vSphere] Attempting to use server configuration: "testvcs" [vSphere] Successfully retrieved IP for "vm-test.ci.kit" : 10.0.24.55 [vSphere] Exposing 10.0.24.55 as environment variable VSPHERE_IP [Pipeline] echo VM IP: null [Pipeline] echo Build_id: 14 [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS   Custom log record: Apr 17, 2018 6:14:17 PM FINE org.jenkinsci.plugins.workflow.job.WorkflowRun PowerOnVmPipeline #13 in /var/lib/jenkins/jobs/PowerOnVmPipeline/builds/13: result is set to SUCCESS java.lang.Exception at org.jenkinsci.plugins.workflow.job.WorkflowRun.setResult(WorkflowRun.java:738) at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:747) at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$1100(WorkflowRun.java:142) at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:1094) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:1413) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$3.run(CpsThreadGroup.java:412) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:35) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 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) Apr 17, 2018 6:14:17 PM INFO org.jenkinsci.plugins.workflow.job.WorkflowRun finish PowerOnVmPipeline #13 completed: SUCCESS  

          I confirm the issue, can't seem to pass anything to the host.

          Szymon Bielawski added a comment - I confirm the issue, can't seem to pass anything to the host.

          Nick Jones added a comment - - edited

          It looks like it should work, but it simply doesn't. I've tried both the ExposeGuestInfo class and the PowerOn class through the vSphere step, and despite the logs indicating that it was exposing an environment variable (in my case, with the IP address of a clone VM), the variable remains null. The relevant pipeline steps (e.g., with PowerOn) look like this:

          vSphere buildStep: [$class: 'PowerOn', timeoutInSeconds: 180, vm: 'Vm1234'], serverName: 'My vSphere Cloud'
          echo "VSPHERE_IP: ${env.VSPHERE_IP}"
          

          But then the logs look like this:

          00:00:08.972  [vSphere] Performing vSphere build step: "Power-On/Resume VM"
          00:00:08.972  [vSphere] Attempting to use server configuration: "My vSphere Cloud"
          00:00:39.341  [vSphere] Successfully retrieved IP for "Vm1234" : 10.50.50.133
          00:00:39.341  [vSphere] Exposing 10.50.50.133 as environment variable VSPHERE_IP
          00:00:39.381  [Pipeline] echo
          00:00:39.381  VSPHERE_IP: null
          

          As this is from a Pipeline job (I tried both Scripted and Declarative syntax), I expect that "run" is not an instance of AbstractBuild (as I expect it's a WorkflowRun instead), and thus it is simply calling env.put with the environment variable in question, according to the source.

          I guess there's a fundamentally different way for environment variables to be set from Pipeline jobs, and it simply doesn't work as this plugin expects it to?

          It works in a Freestyle job with these same build steps, so it does seem to come down to whether the build in question is an AbstractBuild or not.

          Nick Jones added a comment - - edited It looks like it should work, but it simply doesn't. I've tried both the ExposeGuestInfo class and the PowerOn class through the vSphere step, and despite the logs indicating that it was exposing an environment variable (in my case, with the IP address of a clone VM), the variable remains null. The relevant pipeline steps (e.g., with PowerOn) look like this: vSphere buildStep: [$class: 'PowerOn' , timeoutInSeconds: 180, vm: 'Vm1234' ], serverName: 'My vSphere Cloud' echo "VSPHERE_IP: ${env.VSPHERE_IP}" But then the logs look like this: 00:00:08.972 [vSphere] Performing vSphere build step: "Power-On/Resume VM" 00:00:08.972 [vSphere] Attempting to use server configuration: "My vSphere Cloud" 00:00:39.341 [vSphere] Successfully retrieved IP for "Vm1234" : 10.50.50.133 00:00:39.341 [vSphere] Exposing 10.50.50.133 as environment variable VSPHERE_IP 00:00:39.381 [Pipeline] echo 00:00:39.381 VSPHERE_IP: null As this is from a Pipeline job (I tried both Scripted and Declarative syntax), I expect that "run" is not an instance of AbstractBuild (as I expect it's a WorkflowRun instead), and thus it is simply calling env.put with the environment variable in question, according to the source . I guess there's a fundamentally different way for environment variables to be set from Pipeline jobs, and it simply doesn't work as this plugin expects it to? It works in a Freestyle job with these same build steps, so it does seem to come down to whether the build in question is an AbstractBuild or not.

            Unassigned Unassigned
            sjm Scott Miller
            Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: