I am testing powercli with jenkins and I am getting the below error
[EnvInject] - Loading node environment variables.
Building in workspace C:\Program Files (x86)\Jenkins\workspace\mine
[mine] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Windows\TEMP\jenkins6451574485999889179.ps1'"
Import-Module : The specified module 'VMware.VimAutomation.Core' was not
loaded because no valid module file was found in any module directory.
At C:\Windows\TEMP\jenkins6451574485999889179.ps1:1 char:1
+ Import-Module "VMware.VimAutomation.Core"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (VMware.VimAutomation.Core:
String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
ands.ImportModuleCommand
connect-viserver : The term 'connect-viserver' is not recognized as the name
of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try
again.
At C:\Windows\TEMP\jenkins6451574485999889179.ps1:2 char:1
+ connect-viserver $vc -User $user -Password $pass
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (connect-viserver:String) [], Co
mmandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
get-vm : The Hyper-V role is not installed on the destination host. Add the
Hyper-V role on that host and then run this cmdlet again.
At C:\Windows\TEMP\jenkins6451574485999889179.ps1:3 char:1
+ get-vm
+ ~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VM], VirtualizationOperat
ionFailedException
+ FullyQualifiedErrorId : Microsoft.HyperV.PowerShell.Commands.GetVMComman
d
I suspect you are encountering the issue that in Jenkins the $env:PSMOdulePath variable is not populated as it is in an interactive PowerShell session.
See windows - Jenkins environment different to interactive logon - why? - Stack Overflow
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I was able to get the fix the issue for Jenkins. Jenkins is a 32-bit process, running from a Windows service - it executes the x86 PowerShell!
the Modules directory for x86 PowerShell is located under %systemroot%\SysWow64\WindowsPowerShell\1.0\Modules, after specifying this path at master node in Jenkins, PowerCLI in Jenkins started working
Nice find.
Is Jenkins on Windows always a 32-bit process?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference