PreDeploy Step Not Completing

Hi,

I’m using the following code to start an application from a PreDeploy powershell script.
The intention is to start a temporary instance of an app before Deploy.ps1 happens, but the PreDeploy never completes unless I terminate this temporary app instance. The temporary instance of the app will be terminated during the PostDeploy.ps1 (in case you wondered).

Please advise if this is considered possible or perhaps a better way of achieving this.

function StartApp([string] $dir, [string] $app)
{
$exe = $dir + “” + $app + ".exe"
Write-Host “Starting instance for $app ($exe)”

$psinfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo
$psinfo.FileName = $exe
$psinfo.Arguments = “–console”
$psinfo.RedirectStandardError = $true
$psinfo.RedirectStandardOutput = $true
$psinfo.UseShellExecute = $false
$psinfo.WorkingDirectory = $dir

$ps = New-Object -TypeName System.Diagnostics.Process
$ps.StartInfo = $psinfo
$ps.Start()

$line = $ps.StandardOutput.ReadLine()
while ($line -ne $null)
{
Write-Host $line
if ($line.Contains(" Error “))
{
Stop-Process -Id $ps.Id
throw “Deployment aborted”
}
if ($line.Contains(” Registered "))
{
break
}
$line = $ps.StandardOutput.ReadLine()
}

if ($line -eq $null)
{
Stop-Process -Id $ps.Id
Write-Host "Instance failed to start"
throw “Deployment aborted”
}

Set-OctopusVariable -name “PID” -value $ps.Id.ToString()
Write-Host “Instance started”

return $ps
}

StartApp $OctopusOriginalPackageDirectoryPath “MyApp”

Thanks in advance,
Renier

I’m having the same issue just trying to execute a powershell command that calls a function in a script module. The function executes successfully, but the deployment step never ends.

Is there some type of return value that is expected from the powershell script to force the step to end?

Hi Renier,

Thanks for getting in touch!

Unfortunately this seem to be a PowerShell issue as it won’t return until the child process created has been terminated.

I’ve been trying to come up with an alternative solution but have been unable to, you could try to get it running using the Start-Job module that is used to create background jobs, but I can’t say for sure that it will work.

@david.m.caldwell I’m not sure why yours isn’t working, I tried executing a powershell command that calls a function and it returned successfully and the step completed successfully. If you could post what your step looks like I can take a look at that as well.

Hope that helps!

Henrik