Reputation: 1433
I am trying to auto deploy build on azure. For this i use powershell script to upload zip on azure. There is two part of the script -> First to clean the wwwroot folder and second part is to upload zip to wwwroot. It runs successfully when i run script through Powershell exe but gives error when run through Jenkins. Strange thing is, it successfully runs first part but gives error on second part. Powershell Script :
$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"
Error display in Jenkins Console :
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
Upvotes: 0
Views: 694
Reputation: 1433
Finally it works after added couple of thing like timeout, change Method type, security protocol 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"
Upvotes: 1