将其他文件重命名或部署到 Azure Web App
Rename or deploy additional files to Azure Web App
作为 Azure DevOps 发布管道的一部分,我希望在 "Deploy Azure App Service" 任务完成后将一些 .config
文件重命名为 .config.disabled
。
我试图添加一个额外的 "Deploy Azure App Service" 任务,但这似乎覆盖了之前的任务,只留下 wwwroot 中的 .config.disabled
文件。
是否有任何其他方法(除了 FTP 上传任务)可用于 rename/deploy Azure Web 应用程序中的文件子集?
如果您不想使用 FTP,尝试使用支持 Azure Web 应用程序的 Kudu service 可能会取得一些成功。
要查看 Kudu 服务,请导航至 https://<your-web-app-name>.scm.azurewebsites.net
通过身份验证后,您会发现有一种方法可以浏览文件、查看 运行ning 进程和一个交互式控制台,允许您针对 运行 基本 DOS 或 PowerShell 命令文件系统。
交互式控制台很棒,但要使其自动化,您可以使用 REST API 对文件系统发出命令。
issuing commands to the server有几个例子。在 PowerShell 中:
# authenticate with Azure
Login-AzureRmAccount
$resoureGroupName = "your-web-app-name"
$websiteName = "your-resource-group-name"
$env = @{
command= 'Set COMPUTERNAME'
dir= 'site'
}
$json = $env | ConvertTo-Json
$env2 = @{
command= 'copy filename.config file.config.notused'
dir= 'site\wwwroot'
}
$json2 = $env2 | ConvertTo-Json
$env3 = @{
command= 'delete filename.config'
dir= 'site\wwwroot'
}
$json3 = $env3 | ConvertTo-Json
# setup auth header
$website = Get-AzureWebsite -Name $websiteName
$username = $website.PublishingUsername
$password = $website.PublishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api"
[System.Uri]$Uri = $apiBaseUrl
# get all the vms in the web-app
$instances = Get-AzureRmResource -ResourceGroupName $resoureGroupName `
-ResourceType Microsoft.Web/sites/instances `
-ResourceName $websiteName `
-ApiVersion 2018-02-01
#loop through instances
foreach($instance in $instances)
{
$instanceName = $instance.Name
Write-Host "`tVM Instance ID `t`t: " $instanceName
#Now execute 'SET COMPUTER' cmd
$cookie= New-Object System.Net.Cookie
$cookie.Name = "ARRAffinity"
$cookie.Value = $instanceName
$Cookie.Domain = $uri.DnsSafeHost
$session=New-Object Microsoft.Powershell.Commands.WebRequestSession
$session.Cookies.add($cookie)
$response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
-Headers @{Authorization=("Basic {0}" `
-f $base64AuthInfo)} `
-Method Post -Body $json `
-ContentType 'application/json' `
-WebSession $session
Write-Host "`tVM Instance Name `t: " $response
# perform copy file
$response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
-Headers @{Authorization=("Basic {0}" `
-f $base64AuthInfo)} `
-Method Post -Body $json2 `
-ContentType 'application/json' `
-WebSession $session
Write-Host "`tCopy file result `t: " $response
# perform delete file
$response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
-Headers @{Authorization=("Basic {0}" `
-f $base64AuthInfo)} `
-Method Post -Body $json3 `
-ContentType 'application/json' `
-WebSession $session
Write-Host "`tCopy file result `t: " $response
}
文件系统支持基本命令,例如 copy 和 delete,因此您可以轻松地重命名文件。
作为 Azure DevOps 发布管道的一部分,我希望在 "Deploy Azure App Service" 任务完成后将一些 .config
文件重命名为 .config.disabled
。
我试图添加一个额外的 "Deploy Azure App Service" 任务,但这似乎覆盖了之前的任务,只留下 wwwroot 中的 .config.disabled
文件。
是否有任何其他方法(除了 FTP 上传任务)可用于 rename/deploy Azure Web 应用程序中的文件子集?
如果您不想使用 FTP,尝试使用支持 Azure Web 应用程序的 Kudu service 可能会取得一些成功。
要查看 Kudu 服务,请导航至 https://<your-web-app-name>.scm.azurewebsites.net
通过身份验证后,您会发现有一种方法可以浏览文件、查看 运行ning 进程和一个交互式控制台,允许您针对 运行 基本 DOS 或 PowerShell 命令文件系统。
交互式控制台很棒,但要使其自动化,您可以使用 REST API 对文件系统发出命令。
issuing commands to the server有几个例子。在 PowerShell 中:
# authenticate with Azure
Login-AzureRmAccount
$resoureGroupName = "your-web-app-name"
$websiteName = "your-resource-group-name"
$env = @{
command= 'Set COMPUTERNAME'
dir= 'site'
}
$json = $env | ConvertTo-Json
$env2 = @{
command= 'copy filename.config file.config.notused'
dir= 'site\wwwroot'
}
$json2 = $env2 | ConvertTo-Json
$env3 = @{
command= 'delete filename.config'
dir= 'site\wwwroot'
}
$json3 = $env3 | ConvertTo-Json
# setup auth header
$website = Get-AzureWebsite -Name $websiteName
$username = $website.PublishingUsername
$password = $website.PublishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api"
[System.Uri]$Uri = $apiBaseUrl
# get all the vms in the web-app
$instances = Get-AzureRmResource -ResourceGroupName $resoureGroupName `
-ResourceType Microsoft.Web/sites/instances `
-ResourceName $websiteName `
-ApiVersion 2018-02-01
#loop through instances
foreach($instance in $instances)
{
$instanceName = $instance.Name
Write-Host "`tVM Instance ID `t`t: " $instanceName
#Now execute 'SET COMPUTER' cmd
$cookie= New-Object System.Net.Cookie
$cookie.Name = "ARRAffinity"
$cookie.Value = $instanceName
$Cookie.Domain = $uri.DnsSafeHost
$session=New-Object Microsoft.Powershell.Commands.WebRequestSession
$session.Cookies.add($cookie)
$response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
-Headers @{Authorization=("Basic {0}" `
-f $base64AuthInfo)} `
-Method Post -Body $json `
-ContentType 'application/json' `
-WebSession $session
Write-Host "`tVM Instance Name `t: " $response
# perform copy file
$response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
-Headers @{Authorization=("Basic {0}" `
-f $base64AuthInfo)} `
-Method Post -Body $json2 `
-ContentType 'application/json' `
-WebSession $session
Write-Host "`tCopy file result `t: " $response
# perform delete file
$response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
-Headers @{Authorization=("Basic {0}" `
-f $base64AuthInfo)} `
-Method Post -Body $json3 `
-ContentType 'application/json' `
-WebSession $session
Write-Host "`tCopy file result `t: " $response
}
文件系统支持基本命令,例如 copy 和 delete,因此您可以轻松地重命名文件。