Complete Newbie with Jenkins here but...
I'm trying to use Jenkins to run VM automation scripts but I can seem to get the Powercli module loaded so that i can connect to vcenter in the scripts.
When I load PowerShell interactively PowerCLI loads fine and I can exceute commands fine.
I've seen a few posts about environment variables and I've added the Path and PSModulePath variables to the global properties section in the configure systems, but that doesnt change anything.
Also tried runnnig the Jenkins Windows service as my account but the results are always the same. As shown below...
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
import-module : The specified module 'VMware.PowerCLI' was not loaded because
no valid module file was found in any module directory.
At C:\Windows\TEMP\jenkins3243661025460378840.ps1:3 char:1
+ import-module VMware.PowerCLI
Any help would be appreciated here
Jenkins is a pita because of the way the accounts and services are run. Where is the module installed? Is it in any of the folders named in $env:psmodulepath for the user account Jenkins runs under?
The module is installed in the normal location..C:\Windows\System32\WindowsPowerShell\v1.0\Modules
When I run the Jenkins service under my account I still get the same issues but inetractively from the Powershell prompt PowerCli is fine.
Looking at the built tho it still says its running as System
Started by user admin
Running as SYSTEM
Building in workspace C:\Program Files (x86)\Jenkins\workspace\ps-test1
[ps-test1] $ powershell.exe -NonInteractive -ExecutionPolicy Bypass -File C:\Users\DA_HOW~1\AppData\Local\Temp\jenkins4121092801461908652.ps1
import-module : The specified module 'VMware.PowerCLI' was not loaded because no valid module file was found in any
At C:\Users\da_howardm\AppData\Local\Temp\jenkins4121092801461908652.ps1:3 char:1
+ import-module VMware.PowerCLI
+ CategoryInfo : ResourceUnavailable: (VMware.PowerCLI:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.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
So using jenkins in a way its not intended. I have been down this rabbit hole.... How are you calling your scripts? Are you just putting your script into the powershell command block or are you calling it like so? "powershell -File .\VMware\Tools\CDrom\Get-CDrom.ps1"
Ok so that showed a different location.. it showed C:\Program Files (x86)\WindowsPowerShell\Modules
I moved the modules and now that works within Jenkins, but interactively it doesn't' work now...
I also notice I have Powershell 7 installed on here. it must be part of the template....
I'd just been pasting som test POwercli commands straight into Jenkins just to see if everything is working...
So the approach is to get Jenkins to trigger a .ps1 script rather than adding commands here...?
Why don't you automate the installation of the PowerCLI modules as well?
In your build, first check if the modules are there, if not install them.
To be honest, I haven't tested/tried this with PSv7 (which looks for modules in yet another location)
Well with the modules in C:\Program Files (x86)\WindowsPowerShell\Modules running a test ps.1 with Powecli commands works fine.
It runs using the older PowerShell 5.1.14393.3471 and not the v7 thats also installed. I think thats fine for me...
I dont sem to need the import first commands are available straight away...
Thanks very much for your help Guys