【问题标题】:Unable to deploy .zip file using Kudu api to the Azure App Service无法使用 Kudu api 将 .zip 文件部署到 Azure 应用服务
【发布时间】:2021-01-09 00:01:46
【问题描述】:

我在发布管道中使用 PowerShell 内联任务将相应的 zip 文件部署到 Azure 应用服务,但由于以下错误,我无法实现它。如果我在这里缺少任何东西,请告诉我。

我遇到了错误
Invoke-RestMethod:路径 'D:\a\r1\a_CI-VI-Maven/DeployPackages/marnet.zip' 解析为一个目录。指定包含文件名的路径,然后重试该命令。

下面是我使用的脚本:

$username = "用户名"
$password = "密码"

$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"

【问题讨论】:

  • 在本地它就像一个魅力。我也尝试使用 PUT 方法,但仍然存在相同的结果。后来我尝试创建一个示例项目并执行相同的过程,没有代码更改,它按预期工作。我还在解决这个问题。
  • 在下面查看我的答案,您应该更正脚本中$filepath 的值,marnet.zip 是文件夹名称而不是压缩文件,可能真正的文件路径是path/marnet.zip/xx.zip。更正路径,您的问题就会消失。

标签: powershell azure-devops azure-pipelines-release-pipeline kudu


【解决方案1】:

检查您的文件夹结构,您似乎有一个名为marnet.zip的文件夹!

出现问题是因为 $filePath = "$(System.DefaultWorkingDirectory)_CI-VI-Maven/DeployPackages/marnet.zip" 是文件夹 marnet.zip 的路径,而不是真正的 marnet.zip 文件。

我的可重现步骤:

1.当我的s.zip 文件直接位于构建工件文件夹下时,一切正常。

2.在构建管道中更改一些内容以创建s.zip文件夹,并将s.zip文件移动到此文件夹。

3.然后,同样的问题发生:

【讨论】:

  • 它现在工作了,现在可以修复它,感谢大家的回复@Krzysztof Madej
【解决方案2】:

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"

因此,如果您想使用 zip 控制器 API,请将您的动词更改为 PUT insted of POST。

【讨论】:

  • 用PUT方法也试过了,还是一样的问题。
猜你喜欢
  • 2019-09-11
  • 1970-01-01
  • 2020-07-07
  • 2021-02-07
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多