通过Azure管道中的FTP任务将单个静态内容文件部署到Azure应用服务

时间:2020-05-29 15:47:32

标签: azure web ftp azure-pipelines web-deployment

我刚刚将Classic ASP网站升级到ASP.NET Core MVC Razor Page框架。我没有CMS系统,我所有的静态内容文件(.xml),PDF和图像都包含在我的网站项目中。为了部署我的静态内容文件,我在基于目录的Azure管道中使用FTP任务。当我的发布管道运行时,它们删除我的应用程序服务上指定内容目录中的所有内容,然后重新复制与部署关联的目录中的所有内容。使用Classic ASP,我能够使用Web Deploy将单个文件发布到我的prem服务器上,但是由于从prem到云中发布的安全性问题,Web Deploy不再是一个选择。我想部署单个内容文件,而不是发布管道中的整个内容目录。部署增量的能力将是额外的收获。是否有脚本或其他功能可以使我将单个静态内容文件部署到我的应用程序服务中?请注意,由于审核标准的原因,我无法直接在Kudu控制台中编辑文件。

1 个答案:

答案 0 :(得分:0)

您可以使用Kudu api将单个内容文件部署到您的azure应用服务器。

您可以尝试在发布管道中添加脚本任务来调用kudu api。对于下面的示例脚本在Powershell中:

# User name from WebDeploy Publish Profile. Use backtick while assigning variable content  
$userName = "{userName}"  
# Password from WebDeploy Publish Profile  
$password = "{Password}"  
# Encode username and password to base64 string  
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $password)))

#deploy the static files to azure app server.
$filePath = "$(system.defaultworkingdirectory)\content\staticfiles.html";
$apiUrl = "https://websitename.scm.azurewebsites.net/api/vfs/site/wwwroot/staticfiles.html";
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType "multipart/form-data";

您可以在“发布配置文件”中获取用户名和密码。您可以从Azure Web App下载发布配置文件。并在publishProfile部分中引用userName和userPWD值。

您还可以通过 Azure PowerShell 任务中的脚本获取用户名和密码。参见以下示例:

$ResGroupName = ""
$WebAppName = ""

# Get publishing profile for web application
$WebApp = Get-AzWebApp -Name $WebAppName -ResourceGroupName $ResGroupName
[xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp

# Create Base64 authorization header
$username = $publishingProfile.publishData.publishProfile[0].userName
$password = $publishingProfile.publishData.publishProfile[0].userPWD
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

#deploy the static files to azure app server.
$filePath = "$(system.defaultworkingdirectory)\content\staticfiles.html";
$apiUrl = "https://websitename.scm.azurewebsites.net/api/vfs/site/wwwroot/staticfiles.html";
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType "multipart/form-data";

有关更多信息,请参见here

相关问题