[英]Powershell: Jenkins build hangs attempting to invoke remote PS script
so I am using the Jenkins powershell plugin to simply copy my built package over to a remote share, unpack it and invoke another powershell script which performs some application specific installation (it sits in the package). 因此,我使用Jenkins powershell插件将构建的软件包简单地复制到远程共享,解压缩并调用另一个执行特定于应用程序的安装的powershell脚本(它位于软件包中)。
Now what happens is, the build powershell script executes successfully up until I execute the script in the remote share, when it executes that line it just hangs... 现在发生的是,构建powershell脚本成功执行,直到我在远程共享中执行该脚本为止,当它执行该行时,它只是挂起了...
my execution policy on the remote machine is unrestricted. 我在远程计算机上的执行策略不受限制。
Here is a snippet of what I am doing: 这是我在做什么的摘要:
#create temporary session with timeout of 2 minutes
$pso = new-pssessionoption -OperationTimeout 120000
$session = New-PSSession -ComputerName $env:remoteServer -sessionOption $pso
Enter-PSSession $session
#Copy distribution to CD server
Copy-Item $src $deployDir -Recurse -Force
#Locate install script
$installScript = Get-Item($deployDir + "*-distribution\*\install.ps1")
write-host ("Executing install script at location " + $installScript)
#Execute install script
& $installScript $env:installArgs -Y
Please note I am new to writing powershell so apologies if my script is awf :D 请注意,如果我的脚本是awf,我是刚开始编写Powershell的人,因此表示歉意:D
Has anyone experienced this kind of behaviour and could point out what I am missing/doing wrong? 有没有人经历过这种行为,可以指出我想念/做错了什么?
thanks, 谢谢,
Using Enter-PSSession
in a script will cause the script to hang. 在脚本中使用Enter-PSSession
将导致脚本挂起。 Use Invoke-Command
instead. 请改用Invoke-Command
。 BTW if you use the -FilePath parameter it will copy the script from the local PC to the remote PC for you. 顺便说一句,如果您使用-FilePath参数,它将为您将脚本从本地PC复制到远程PC。 However, if that script references other scripts you'll have to copy those. 但是,如果该脚本引用了其他脚本,则必须复制这些脚本。
Invoke-Command -session $session -FilePath c:\somepath\install.ps1 -Arg "$env:InstallArgs -Y"
If you want to handle the copying yourself then do something like this: 如果您想自己处理复制,请执行以下操作:
Invoke-Command -session $session -Arg $src,$deployDir,$env:installArgs -Scriptblock {
param($src, $deployDir, $installArgs)
Copy-Item $src $deployDir -Recurse -Force
$installScript = GetItem "$deployDir*-distribution\*\install.ps1"
& $installscript "$installArgs -Y"
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.