VMware Cloud Community
MrGallus23
Contributor
Contributor

VM Deployment with Jenkins and Powercli (Part 2!)

SO back in April I was having issue switch Jenkins running powercli... its been an age since I looked at this so I decided to start form a clean slate.

with a new VM (2016) and Jenkins install. I'm also retrieving by powershell form GitHub.

All seems well but when I attempt to create a new VM I get 

[11-11-2020_11-47-12]-Checking IP Adddress...
[11-11-2020_11-47-16]-IP address is unused continuing
[11-11-2020_11-47-16]-Checking Computer name is available.
[11-11-2020_11-47-17]-Finding Computer AD Account
[11-11-2020_11-47-18]-Computer name is available... Continuing
[11-11-2020_11-47-18]-Connecting to vCenter...
Name Port User
---- ---- ----
vcenter 443 xxx\svc_vmdeploy
[11-11-2020_11-47-22]-Checking if VM name already exsits...
[11-11-2020_11-47-22]-VM does not exist in vCenter, continuing...
[11-11-2020_11-47-22]-Finding the best datastore
[11-11-2020_11-47-24]-CCDC2TST999 will be deployed to xxx-NFS-xx
[11-11-2020_11-47-24]-Get 2016 Content Library item and provision New VM called CCDC2TST999
NEW-VM : 11/11/2020 11:47:24 New-VM Could not find item C:\Users\svc_jenkins\AppData.
At C:\Users\svc_jenkins\AppData\Local\Jenkins\.jenkins\workspace\VM Deployment\VM-Deploy\New-deploy.ps1:519 char:5
+ NEW-VM -Name $vmname -ResourcePool $cluster -Location $folder -d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Build step 'PowerShell' marked build as failure
Finished: FAILURE

but powercli is loading fine as I can connect to vcenter and list query objects... Ive also confirmed permissions  and that's also fine...

 

Any ideas ????

 

Mike.

Tags (2)
Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

Can you add the Verbose switch on the New-VM cmdlet and start a transcript log (Start-Transcript) in that New-deploy.ps1 script?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
MrGallus23
Contributor
Contributor

This is the output..

PS>TerminatingError(New-VM): "11/11/2020 13:01:59 New-VM Could not find item C:\Users\svc_jenkins\AppData. "
>> TerminatingError(New-VM): "11/11/2020 13:01:59 New-VM Could not find item C:\Users\svc_jenkins\AppData. "
>> TerminatingError(New-VM): "11/11/2020 13:01:59 New-VM Could not find item C:\Users\svc_jenkins\AppData. "
NEW-VM : 11/11/2020 13:01:59 New-VM Could not find item C:\Users\svc_jenkins\AppData.
At C:\Users\svc_jenkins\AppData\Local\Jenkins\.jenkins\workspace\VM Deployment\VM-Deploy\New-deploy.ps1:521 char:5
+ NEW-VM -Name $vmname -ResourcePool $cluster -Location $folder -d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

**********************
Windows PowerShell transcript end
End time: 20201111130200

for completeness this is the command I'm running

 NEW-VM -Name $vmname  -ResourcePool $cluster -Location $folder -datastore $datastore -Verbose
Reply
0 Kudos
LucD
Leadership
Leadership

I have no clue where this "New-VM Could not find item C:\Users\svc_jenkins\AppData" is coming from.

You could do some further diagnostics like listing the modules, listing the environment variables ... inside your .ps1 script.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
MrGallus23
Contributor
Contributor

How about the attached ?

 

 

Reply
0 Kudos
LucD
Leadership
Leadership

Besides the fact that you have PowerCLI modules installed in two locations (C:\Program Files\WindowsPowerShell\Modules and C:\Windows\system32\WindowsPowerShell\v1.0\Modules), I don't see anything that might explain the issue you are having.

Is that a Template you are using from the Content Library?
You might try to use a regular template in the vCenter as a test.

The New-VM is apparently trying to fetch something from the local drive.
You could consider using something like FileMon to see what it is actually trying to fetch.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
MrGallus23
Contributor
Contributor

Downloaded process mon and did a test... powershell.exe and java are both hitting that folder. 

all the PowerShell entries result in success. but there are hundreds of java entries.

Ive commented the content library item out now and the script is literally just doing a NEW-VM still with the same results.

I may try a tidy up and reinstall of PowerShell...maybe to a lower version

Reply
0 Kudos
vmyrmc
Contributor
Contributor

Did you ever find a solution to this?  I am having the same issue.

Reply
0 Kudos
vmyrmc
Contributor
Contributor

If it helps anyone else, I just figured out how to get this working.  For some reason, it doesn't like the directory it is running in.  If you change the working directory before running New-VM (cd 'C:\test'), then it runs the command without the error.

Reply
0 Kudos
Juntoj
Contributor
Contributor

 

i am also facing issue.

if i run the script directly on power shell or power shell ISE no errors. but same script when i convert ps1 to exe it giving the below error.

i am running so many VMware scripts in exe mode and  all are working fine. Only this New-VM command is not working from exe.

first i have converted to exe using the powergui. it is giving the error. I thought some path issue on powergui. then i converted to exe using iexpress but still same error. i don't know where it getting the local error.  is this issue related environmental variable?

error

20-Dec-2021 04:17:36 - INFO | Selecting datastore
PS>TerminatingError(New-VM): "12/20/2021 4:17:42 AM New-VM Could not find item C:\Users\SXXX\AppData. "
>> TerminatingError(New-VM): "12/20/2021 4:17:42 AM New-VM Could not find item C:\Users\SXXX\AppData. "
12/20/2021 4:17:42 AM New-VM Could not find item C:\Users\SXXX\AppData.
New-VM : 12/20/2021 4:17:42 AM New-VM Could not find item C:\Users\SXXX\AppData.
At D:\SA_Help_Automation\Scripts-test\pmatts_srts\VM_Shell_Create_V1.ps1:223 char:25
+ ... ){$output = New-VM -Name $VMname -ResourcePool $ESXi -Datastore $Data ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Reply
0 Kudos