views:

198

answers:

3

I am trying to invoke powershell during the preSync call in a MSDeploy command, but powershell does not exit the process after it has been called. The command (from command line): "tools/MSDeploy/msdeploy.exe" -verb:sync -preSync:runCommand="powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command C:/MyInstallPath/deploy.ps1 Set-WebAppOffline Uninstall-Service ",waitInterval=60000 -usechecksum -source:dirPath="build/for-deployment" -dest:wmsvc=BLUEPRINT-X86,username=deployer,password=deployer,dirPath=C:/MyInstallPath

I used a hack here (http://therightstuff.de/2010/02/06/How-We-Practice-Continuous-Integration-And-Deployment-With-MSDeploy.aspx) that gets the powershell process and kills it but that didn't work. I also tried taskkill and the sysinternals equivalent, but nothing will kill the process so that MSDeploy errors out. The command is executed, but then just sits there. Any ideas what might be causing powershell to hang like this? I have found a few other similar issues around the web but no answers.

Environment is Win 2K3, using Powershell 2.0.

UPDATE: Here is a .vbs script I use to invoke my powershell command now. Invoke using 'cscript.exe path/to/script.vbs':

Option Explicit
Dim oShell, appCmd,oShellExec
Set oShell = CreateObject("WScript.Shell")
appCmd = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ""&{ . c:/development/materialstesting/deploy/web/deploy.ps1; Set-WebAppOffline }"" "
Set oShellExec = oShell.Exec(appCmd)
oShellExec.StdIn.Close()
A: 

Have you tried using this command? stop-process $pid . $pid is a built in powershell variable for the current pid. I have this working on a server 2008 R2 server, for the codecampserver project. You can view the build that runs this here: http://build-oss.headspringlabs.com. I have note tried this from a pre-sync but I do not think that should effect the remote session.

Eric Hexter
EricI think that is actually your code I started with! :) I am running on Win 2K3 and it still doesn't work with any of the Stop-Process calls. I had to workaround hosting PS in wscript to kill StdIn.
SonOfNun
wow, good to know .. this really sounds like a bug. stop-process should act the same across the various server OS.
Eric Hexter
A: 

Look at the proposed solution on this site. It appears that PowerShell.exe doesn't want to exit when executed like this until its stdin has been closed by the invoking process.

Keith Hill
Keith, This did in fact solve the problem.I also tried [Console]::In.Close() within the ps1 and it didn't work so I guess I have to host in wscript. Thanks alot!
SonOfNun
A: 

Just in case someone is looking for a similar solution for a batch file: Have a look here http://epeleg.blogspot.com/2010/06/solution-to-powershell-never-exists.html

epeleg