通过 Azure Pipelines 中的 FTP 任务将单个静态内容文件部署到 Azure App 服务中。

问题描述 投票:-1回答:1

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

azure web ftp azure-pipelines web-deployment
1个回答
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";

请看 此处 更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.