我正在尝试在Azure上自动部署构建。为此我使用powershell脚本在azure上传zip。脚本有两部分 - >首先清理wwwroot文件夹,第二部分是将zip上传到wwwroot。当我通过Powershell exe运行脚本时它运行成功但在运行Jenkins时出错。奇怪的是,它成功地运行了第一部分,但在第二部分给出了错误。 Powershell脚本:
$username = "`$347testpass"
$password = "xyz"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"
#Clean wwwroot folder
$apiUrl1 = "https://347testpass.scm.azurewebsites.net/api/command"
$commandBody = @{
command = "rmdir D:\home\site\wwwroot /Q /S"
}
Invoke-RestMethod -Uri $apiUrl1 -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST ` -ContentType "application/json" -Body (ConvertTo-Json $commandBody) | Out-Null
#Upload zip file
$apiUrl = "https://347testpass.scm.azurewebsites.net/api/zip/site/wwwroot/"
$filePath = "D:\AzureWeb\Upload\qwerty.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType "multipart/form-data"
Jenkins控制台中显示错误:
Invoke-RestMethod : The request was aborted: The request was canceled.
At C:\Users\Harsh.Sharma\AppData\Local\Temp\hudson8158442147919891501.ps1:34
char:1
+ Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f
$base64A ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], WebExcept
ion
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Com
mands.InvokeRestMethodCommand
答案 0 :(得分:1)
最后它添加了一些东西,如超时,更改方法类型,安全协议tls12。
$apiUrl = "https://347testpass.scm.azurewebsites.net/api/zipdeploy"
$filePath = "C:\BuildDeploymentAzureEnterprise3.4\Unzipped\AzureBuildFiles.zip"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-RestMethod -Uri $apiUrl -DisableKeepAlive -TimeoutSec 1000 -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $filePath -ContentType "multipart/form-data"
答案 1 :(得分:0)
尝试将-DisableKeepAlive
与Invoke-RestMethod
一起使用。