无法使用Kudu api将.zip文件部署到Azure应用服务

问题描述

我正在发布管道中使用PowerShell内联任务将各自的zip文件部署到Azure App Service,但是由于以下错误,我无法实现它。您能否让我知道这里是否缺少任何东西。

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

enter image description here

以下是我正在使用的脚本:

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

解决方法

正在寻找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,请将您的动词更改为由POST插入的PUT。

,

检查您的文件夹结构,看来您有一个名为const isProduction = process.env.NODE_ENV === 'production'; module.exports = { plugins: [ require('postcss-import'),require('tailwindcss')('./tailwind.config.js'),require('autoprefixer'),require('postcss-preset-env')({ browsers: ['last 2 versions','> 5%'],}),require('cssnano'),],}; 的文件夹!

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

我的可重复步骤:

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

2。更改Build管道中的内容以创建s.zip文件夹,并将s.zip文件移动到该文件夹​​。

enter image description here

3。然后,出现相同的问题:

enter image description here