[英]Deploy Individual Static Content Files to Azure App Service Via FTP Task in Azure Pipelines
I've just upgraded a Classic ASP website to an ASP.NET Core MVC Razor Page framework.我刚刚将经典 ASP 网站升级到 ASP.NET 核心 MVC Razor 页面框架。 I do not have a CMS system and all of my static content files (.xml), PDFs, and images are contained in my website project.
我没有 CMS 系统,我的所有 static 内容文件 (.xml)、PDF 和图像都包含在我的网站项目中。 To deploy my static content files, I'm using FTP tasks within Azure pipelines that are based on directory.
为了部署我的 static 内容文件,我在基于目录的 Azure 管道中使用 FTP 任务。 When my release pipelines run, they delete all of the content within the designated content directory on my app service and then re-copy all of the content that was in the directory associated with the deployment.
当我的发布管道运行时,它们会删除我的应用服务上指定内容目录中的所有内容,然后重新复制与部署关联的目录中的所有内容。 With Classic ASP, I was able to use Web Deploy to publish individual files to my on prem servers, however, Web Deploy is no longer an option due to security issues with publishing from on prem to the cloud.
使用 Classic ASP,我可以使用 Web Deploy 将单个文件发布到我的本地服务器,但是,由于从本地发布到云的安全问题,Web Deploy 不再是一个选项。 I'd like to deploy individual content files, instead of an entire content directory within my release pipelines.
我想在我的发布管道中部署单个内容文件,而不是整个内容目录。 The ability to deploy deltas would be an added bonus.
部署增量的能力将是一个额外的好处。 Is there a script or other functionality available that would allow me to deploy individual static content files to my app services?
是否有可用的脚本或其他功能允许我将单个 static 内容文件部署到我的应用服务? Please note I'm not able to edit the files directly within the Kudu console, due to audit standards.
请注意,由于审核标准,我无法直接在 Kudu 控制台中编辑文件。
You can use Kudu api to deploy individual content files to your azure app server.您可以使用 Kudu api 将单个内容文件部署到您的 azure 应用服务器。
You can try adding a script task to call kudu api in your release pipeline.您可以尝试在发布管道中添加脚本任务来调用 kudu api。 For below example scripts in powershell:
对于 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";
You can get the username and password in the Publish Profile.您可以在发布配置文件中获取用户名和密码。 You can download the publish profile from the Azure Web App.
您可以从 Azure Web 应用程序下载发布配置文件。 And refer userName and userPWD values in the publishProfile section.
并参考 publishProfile 部分中的 userName 和 userPWD 值。
You can also get the username and password via scripts in Azure PowerShell task.您还可以通过Azure PowerShell任务中的脚本获取用户名和密码。 See below example:
请参见下面的示例:
$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";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.