简体   繁体   English

将单个 Static 内容文件部署到 Azure 应用程序服务,通过 Z3A580FZ0Pipeline 中的 FTP 任务

[英]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";

See here for more information.请参阅此处了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Azure Pipelines将Spring Boot App部署到Azure App Service - Deploy Spring Boot App to Azure App Service via Azure Pipelines 通过 gitlab ci 部署 vue 到 azure static Z2567A5EC9705061AC2CZ98403 - Deploy vue via gitlab ci to azure static web app (service) Azure 应用服务 - 从 Azure Pipelines 部署后出现内存错误 - Azure App Service - Memory errors after deploy from Azure Pipelines 如何使用Azure App Service部署任务通过VSTS将多个jar文件上传到Azure - How to upload multiple jar files into Azure through VSTS using Azure App service deploy task 使用 azure devops 管道将控制台 webjob 应用程序部署到包含 webapi 的 azure 应用程序服务 - Deploy console webjob app to azure App service containing a webapi using azure devops pipelines 如何通过 FTP 访问我的 Azure 应用服务文件? wwwroot 目录为空 - How do I access my Azure App Service Files via FTP? The wwwroot directory is empty 使用 azure 管道部署 create-react-app - Deploy create-react-app with azure pipelines 如何使用Azure DevOps在Nure应用服务上部署Nupkg文件 - How to deploy nupkg files on azure app service using azure devOps TFS 2015缺少“部署Azure应用服务”任务 - TFS 2015 is missing the “Deploy Azure App Service” task URL无法访问通过FTP传输到Azure应用服务的文件 - Files transfered via FTP to Azure app services are not accessible with URLS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM