Automation

 View Only
Expand all | Collapse all

Powercli on CentOS7 & Jenkins

  • 1.  Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 01:15 AM

    Hi

     

    I installed Powercli on Centos & all works well.

     

    pwsh
    PowerShell 7.1.0
    Copyright (c) Microsoft Corporation.

     

    And get-vm etc works well

     

    Now i added a Jenkin job, as below

     

    Find-Module "VMware.PowerCLI" | Install-Module -Scope "AllUsers" -AllowClobber
    Set-PowerCLIConfiguration -InvalidCertificateAction "Ignore" -confirm:$false

    Import-Module "VMware.PowerCLI"



    connect-viserver -Server xxx.xxx.xxx.com -User xxx@xxx.xxx.com -Password "xxx#"

    Get-VM | Get-Snapshot | Where {$_.Created -lt ((Get-Date).AddDays(-3))}| Select-Object VM, Name, Created, SizeGB,@{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}}


    #

     

     

    but the job fails & says it can not find connect-viserver  or even get-vm

     

     

    i saw notes here which talk about the path etc..  any suggestions Please ?

     

    thanks



  • 2.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 01:25 AM

    for test i change the script to simple write-output & it worked well

     

    Running as SYSTEM
    Building in workspace /var/lib/jenkins/workspace/Vmware-SnapShots-Reminder
    [Vmware-SnapShots-Reminder] $ pwsh -NonInteractive -NoProfile -File /tmp/jenkins16290d409644183.ps1
    test
    Finished: SUCCESS

    #######################################








  • 3.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 01:28 AM

    in google all i see folks running powershell/powercli on Jenkins running on windows .. not many i saw doing what i am doing ..

     

    i am sure all i am missing something small thing on seting env of path ..



  • 4.  RE: Powercli on CentOS7 & Jenkins
    Best Answer

    Posted Nov 21, 2020 05:48 AM

    Did you check what is defined in $env:PSModulePath (from within a Jenkins triggered PS script)?
    Most of the issues with Jenkins and PS seem to be originating from incorrect content in $env:PSModulePath.



  • 5.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 07:00 AM

    I am going to try ...

     

    I worked around this by explicitly adding the path as an environment variable to Jenkins, but I don't know why I had to do that. Anyway it works now

     

    .. My  jenkins user's path i will try add  powercli .. i have to find where it installed new modules ..

     

    Not sure where i can setup in Linux ... $env:PSModulePath

     

    doing some google on that



  • 6.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 07:03 AM

    find / -name connect-viserver*

     

    giving nothing ... trying to find the path



  • 7.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 07:06 AM

    could be

     

    /opt/microsoft/powershell/7/Modules

     

    i see lot of stuff here ..



  • 8.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 07:08 AM

    /root/.local/share/powershell/Modules/

     

    seems more promising ..



  • 9.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 07:15 AM

    it seems its already setup

     

    PS /root> $env:PSModulePath
    /root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules
    PS /root>

     

     



  • 10.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 07:16 AM

    i think i found the issue .. i will rsync the modules to below

     

    PS /var/lib/jenkins> $env:PSModulePath
    /var/lib/jenkins/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules
    PS /var/lib/jenkins>

     

     

    The ones i have are with root user ..

     

     



  • 11.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 07:56 AM

      thanks as always it helped.

     

    Any suggestions what i can do for below

     

    WARNING: The command 'Send-MailMessage' is obsolete. This cmdlet does not guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell, we recommend you do not use Send-MailMessage at this time. See https://aka.ms/SendMailMessage for more information

    NTLM authentication is not possible with default credentials
    on this platform.

     



  • 12.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 10:49 AM

    It is still a warning.

    And as the message states there is currently no replacement.
    Only in a hyper-secure environment, I would consider using an alternative, but then again would I run SMTP in such an environment 



  • 13.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 11:03 PM

      thanks for reply, not sure if you saw the other message , it seems Jenkins issue & not Powercli

    Basically i did not got the email is the issue

    NTLM authentication is not possible with default credentials
    on this platform.


  • 14.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 21, 2020 11:12 PM

    Ran the script on powershell on windows & it worked  so seems Jenkins's  powershell plugin issue ...

     

    I wished we had such forum as Powershell for Jenkins ... those folks are no aware near our powercli community ..

     

    I wonder   you seems do manage this community to a great extent  single handedly ... ( I/we are fortunately & grateful for that )   is that your passion or this is part of your day job responsibility too 

     

    I am sure this takes some time of yours !

     

     



  • 15.  RE: Powercli on CentOS7 & Jenkins

    Posted Nov 22, 2020 09:08 AM

    VMware used to be part of my day job, and PowerShell/PowerCLI is a passion 
    Since the beginning of this year, I'm retired.
    As long as I can follow the technology developments, I'll continue participating in this forum.

    And yes, I would hope more and more platforms/applications realise that PowerShell is a popular automation tool.
    And would support it.