Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect-OctoServer powersell connection not maintained #19

Open
andreister opened this issue Apr 22, 2019 · 2 comments
Open

Connect-OctoServer powersell connection not maintained #19

andreister opened this issue Apr 22, 2019 · 2 comments

Comments

@andreister
Copy link

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 a direct "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
@Swoogan
Copy link
Owner

Swoogan commented Apr 25, 2019

This is by design. Albeit a bad design. The variable set by the connect command is scoped to your terminal session and isn't available in modules. I will investigate improving this.

@andreister
Copy link
Author

Understood - thanks for the answer 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants