0
votes

I'm using PowerShell inline task in the release pipeline to deploy the respective zip file to the Azure App Service, but im unable to achieve it due to the below error. Can you please let me know if there is any thing that im missing here.

I'm getting below error
Invoke-RestMethod : Path 'D:\a\r1\a_CI-VI-Maven/DeployPackages/marnet.zip' resolves to a directory. Specify a path including a file name, and then retry the command.

enter image description here

Below is the script that im using:

$username = "username"
$password = "pwd"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password))) $userAgent = "powershell/1.0"

$apiUrl = "https://{appservice}.scm.azurewebsites.net/api/zip/site/wwwroot/webapps/"
$filePath = "$(System.DefaultWorkingDirectory)_CI-VI-Maven/DeployPackages/marnet.zip"

Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $filePath -ContentType "multipart/form-data"

2
In local it works like a charm. I tried using the PUT method as well and still the same result persist. Later I tried creating a sample project and did the same process, with no code changes, it works as expected. I'm still figuring out the issue.Raghu Hoskote
Check my answer below, you should correct the value of $filepath in your script, the marnet.zip is a folder name instead of a zip file, maybe the real file path is path/marnet.zip/xx.zip. Correct the path and your issue would go away.LoLance

2 Answers

0
votes

Check your folder structure, it seems that you have a folder named marnet.zip!

Your issue occurred since the $filePath = "$(System.DefaultWorkingDirectory)_CI-VI-Maven/DeployPackages/marnet.zip" is a path to folder marnet.zip instead of a real marnet.zip file.

My reproducible steps:

1.Everything works well when my s.zip file locates directly under build artifacts folder.

2.Change something in Build pipeline to create s.zip folder, and move the s.zip file to this folder.

enter image description here

3.Then, same issue occurs:

enter image description here

0
votes

Looking here

$username = "`$website"
$password = "pwd"
# Note that the $username here should look like `SomeUserName`, and **not** `SomeSite\SomeUserName`
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"

# Example 1: call the zip controller API (which uses PUT)
$apiUrl = "https://{sitename}.scm.azurewebsites.net/api/zip/site/wwwroot/"
$filePath = "C:\Temp\books.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType "multipart/form-data"

# Example 2: call the zipdeploy API (which uses POST)
$apiUrl = "https://{sitename}.scm.azurewebsites.net/api/zipdeploy"
$filePath = "C:\Temp\books.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST -InFile $filePath -ContentType "multipart/form-data"

So if you want to use zip controller API please change your verb to PUT insted of POST.