Azure 项目 Kudu 接受上传的 zip 文件到 Zipdeploy 端点但不部署

Azure project Kudu accepts uploaded zip file to the Zipdeploy endpoint but does not deploy

我有一个 ASP.NET Core 2.0 API 作为 Azure 应用程序服务,带有用于 QA 的部署插槽,我已经使用了几个月。我在 VS2017 中开发,并使用项目的内置发布到 Azure 应用服务组件发布到 Azure。这工作得很好。

我现在正在尝试将部署移动到 Bamboo 部署服务器。

我通常遵循与此类似的过程 link how to use azure kudu zipdeploy from a bamboo deployment server

在我的 Bamboo 构建中,我 运行 调用 dotnet publish 的 Powershell 脚本将发布文件放在输出文件夹中,然后我将这些文件压缩到一个 zip 文件中并将其用作工件。然后,在我的 Bamboo 部署项目中,我引用了该工件和 运行 一个使用 Invoke-WebRequest 调用 Kudu 端点的 Powershell 脚本,如下所示;

Invoke-WebRequest -Uri "https://userName:userPassword@MySiteDeploymentSlot.scm.azurewebsites.net/api/zipdeploy" `
-InFile zipfileName -ContentType "multipart/form-data" -Method Post -UseBasicParsing   

用户名和用户密码是我从 Azure 门户中部署槽的发布配置文件中获得的,ZipFileName 是工件中的 zip 文件,它是我的项目的压缩发布输出。

注意:我现在正在使用 Kudu URL 中的实际值,只是为了让进程正常工作,而不会出现在作为参数传递给 Powershell 时必须反勾用户名和密码属性的问题其他人在使用 Powershell 进行此过程时报告过。

当脚本 运行s 时,我得到以下内容

StatusCode        : 200
StatusDescription : OK
Content           : 

                    <!DOCTYPE html>
                    <html dir="ltr" class="" lang="en">
                    <head>
                        <title>Sign in to your account</title>
                        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                        <meta http-eq...
RawContent        : HTTP/1.1 200 OK
                    Pragma: no-cache
                    Strict-Transport-Security: max-age=31536000; includeSubDomains
                    X-Content-Type-Options: nosniff
                    X-Frame-Options: DENY
                    x-ms-request-id: 31607f18-c30a-46f3-bdaf-d84a...
Forms             : 
Headers           : {[Pragma, no-cache], [Strict-Transport-Security, max-age=31536000; includeSubDomains], 
                    [X-Content-Type-Options, nosniff], [X-Frame-Options, DENY]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : 
RawContentLength  : 34599

由于我收到状态代码 200,我假设它已上传,但当我查看 Kudu 部署端点时它没有出现在部署列表中。

我的理解是,您只需将 zip 文件上传到 Kudu zipdeploy 端点,它就会部署到指定的 Azure 部署槽。但是当我在 Kudo 中查看该站点的文件日期时,它们都是我一周前在 VS2017 中所做的最后一次发布的指示。

显然,我在这里遗漏了一些东西。

从 ZipDeploy 返回的响应,即使它是状态 200,在标题部分标题 属性 中有文本 "Sign in to your account"。我还看到了 DENY (X-Frame-Options: DENY) 这个词,但我不知道这是否与我遇到的问题有关。

有什么想法吗?

我认为问题在于 Invoke-WebRequest 不尊重在 URL 中传递的信誉。相反,您需要显式传递基本身份验证 header。

尝试这样的事情:

$webapp = "MyApp"
$username = "`$MyApp"
$password = "ThePasswordFromPublishProfile"
# 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)))

$apiUrl = "https://$webapp.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"

另请参阅 here 了解相关信息。