我在powershell脚本中使用此函数将war文件部署到tomcat服务器。其他tomcat命令(stop,undeploy,list等)的类似函数工作正常。当我从shell运行脚本时,它可以工作。当我从Jenkins Powershell插件运行脚本时,它失败了。
Function DeployTomcatWebApp([PSCredential]$cred, [string]$server, [string]$app)
{
Write-Host "Deploying $app"
$uri = $server+"/manager/text/deploy?path=/$app&update=true"
$warpath = ($pwd).path + "/$app/build/dev/$app.war"
$r = Invoke-WebRequest -Uri $uri -Credential $cred -InFile $warpath -UseBasicParsing -Verbose -Debug -Method PUT -TimeoutSec 30000 -DisableKeepAlive
Write-Host $r.Content
Return $r
}
控制台日志显示
Deploying DERF
D:\Jenkins\workspace\JenkinsTest_2_AD_DERF\DERF\build\dev\DERF.war
http://mytomcat:8080/manager/text/deploy?path=/DERF&update=true
VERBOSE: PUT http://mytomcat:8080/manager/text/deploy?path=/DERF&update=true with -1-byte payload
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At C:\Users\<jenkinsuser>\AppData\Local\Temp\jenkins1024175502034764284.ps1:49 char:10
+ $r = Invoke-WebRequest -Uri $uri -Credential $cred -InFile $warpa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Jenkins Powershell插件从jenkins作业中提取脚本,并在Local / Temp中创建.ps1文件,并通过调用
执行脚本powershell -NonInteractive -ExecutionPolicy Bypass <tempscriptname>
我很难过,并且正在寻找调试这个的任何见解。