Jenkins Powershell Invoke-Command with Environment Variables

354 views
Skip to first unread message

Gavin Armitage (AU)

unread,
Jun 2, 2016, 1:24:59 AM6/2/16
to Jenkins Users
Hi All,

Busy working on a poc on Jenkins, so really new. So my question is as follows,

1. Running a "master" Powershell script to open a session and using invoke-command with the -File switch including the session

    $cred = New-Object System.Management.Automation.PSCredential -ArgumentList $User, $UserPassword

    $session = New-PSSession -ComputerName $ServerName -Credential $cred

    Invoke-Command -Session $session -FilePath C:\Development\Scripts\001_BaselineMountStorage.ps1 -ArgumentList $p1,$p2,$p3,$p4

Now I can output the environment variables from the "master" powershell script but get a blank when access them from the invoke-command powershell script (in this case 001_BaselineMountStorage.ps1)

How can i access the environment variables from within the invoked script? Could pass them as arguments, but what would happen if they are secret?



Regards,

Gavin
Reply all
Reply to author
Forward
0 new messages