Connect-OctoServer powersell connection not maintained


(andrew.kazyrevich) #1

Looks like “Connect-OctoServer” does not work if calls are done between ps1 file and psm1 module, is that expected?

Using Octopus-CmdLets 0.4.4 and Powershell 5.1

Test.psm1

function Get-EnvironmentViaModule()
{
    "getting all environments..."
    Get-OctoEnvironment
}
Test.ps1

Import-Module .\Test.psm1

$ApiKey = "API-xxxx"
$Url = "https://octopus.xxx.com" 
Connect-OctoServer -Server $Url -ApiKey $ApiKey
"connected..."
Get-EnvironmentViaModule # this fails - but "Get-OctoEnvironment" works

Execution:

> .\Test.ps1
connected...
getting all environments...
Get-OctoEnvironment : Connection not established. Please connect to your Octopus Deploy instance with
Connect-OctoServer
At C:\Users\andrew\Test.psm1:4 char:5
+     Get-OctoEnvironment
+     ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-OctoEnvironment], Exception
    + FullyQualifiedErrorId : System.Exception,Octopus_Cmdlets.GetEnvironment

#3

Hi Andrew

Thanks for getting in touch!

Looking at the information provided your are using the powershell cmdlets from here. As these cmdlets aren’t created or supported by us I would start by raising an issue with the creator.

Sorry I can’t be of more help.

Regards,
Alex