Search code examples
powershellazure-devopsazure-pipelines-release-pipelinekudu

Unable to deploy .zip file using Kudu api to the Azure App Service


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"


Solution

  • 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