AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
321 stars 131 forks source link

New-JiraSession does not wait to complete. #413

Closed donwlewis closed 4 years ago

donwlewis commented 4 years ago

Description

When using New-JiraSession in a custom function, it appears that the function will continue on without waiting for the cmdlet to finish.

Steps To Reproduce

Write a function that uses the New-JiraSession cmdlet and try to run it. You will notice command that are written after the New-JiraSession line will run even the the cmdlet hasn't completed.

Expected behavior

I would expect the function to wait fo the cmdlet to finish before moving on.

Screenshots

Your Environment


Name   Version
----   -------
JiraPS 2.14.0

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Darwin 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan  9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
lipkau commented 4 years ago

Thank you for reporting this. this is not a bug. And actually this is also not happening. The output on the console is indeed in the wrong order and makes you believe it's a problem in the behavior. But actually it's only the output to the console which is wrong.

host output tends to appear before standard output regular output gets a minimum 300ms delay so the formatter has time to see if it needs to group objects into tables etc

If you do

$session = New-Session -Cred $cred
Write-Host "the user is $($session.Username)"

you will see that the behavior is indeed fine.

Note: with the next jira version, New-JiraVersion will no longer output data by default, but offer a -Passthru parameter

donwlewis commented 4 years ago

I think you dismissed this too soon. You may be correct, but it does not work properly. If you try running the following function:

function Test {
    param (
            $Server,
            $Creds
    )
    Set-JiraConfigServer -Server $Server
    New-JiraSession -Credential $Creds
    Write-Host "I am here"
    Get-JiraProject
}

You will see that you never get a list of projects back. Its like the Get-JiraProject command runs before the session is fully established.

lipkau commented 4 years ago

In my console I see that the output of the commands break the console, but the commands are run just fine demo:

$out = test -server … -cred $cred
$out | gm
$out[0]
$out[1]
$out[2]

by storing the session in a variable, it works properly:

function Test {
    param (
            $Server,
            $Creds
    )
    Set-JiraConfigServer -Server $Server
    $null = New-JiraSession -Credential $Creds
    Write-Host "I am here"
    Get-JiraProject
}
donwlewis commented 4 years ago

Thanks @lipkau for clarification.