简体   繁体   中英

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. I do not have a CMS system and all of my static content files (.xml), PDFs, and images are contained in my website project. To deploy my static content files, I'm using FTP tasks within Azure pipelines that are based on directory. 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. 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? Please note I'm not able to edit the files directly within the Kudu console, due to audit standards.

You can use Kudu api to deploy individual content files to your azure app server.

You can try adding a script task to call kudu api in your release pipeline. For below example scripts in 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. And refer userName and userPWD values in the publishProfile section.

You can also get the username and password via scripts in Azure PowerShell task. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM