【问题标题】:Update string in file in web app deployed on microsoft Azure PAAS更新部署在 Microsoft Azure PAAS 上的 Web 应用程序中的文件中的字符串
【发布时间】:2018-05-05 18:13:35
【问题描述】:

我在应用服务中部署了文件。我想在文件中更新字符串 stringToReplace

stringToReplace

  1. 不想重新部署
  2. 想要使用 powershell 更新文件字符串(不是手动)

【问题讨论】:

  • 如果是config文件,可以尝试使用kudu更新文件。

标签: azure azure-web-app-service paas


【解决方案1】:

看来我们没有办法直接用 powershell 做到这一点。您可以将your idea 提供给 Azure WebApp 团队。

  • 不想重新部署
  • 想要使用 powershell 更新文件字符串(不是手动)

根据我的经验,我建议您可以使用 Azure Kudu VFS API 获取文件内容并替换您想要的字符串并将其放入新内容以在 Azure 上归档。然后您将无需重新部署 azure webapp,只需更新您想要的单个文件..

GET /api/vfs/{path}
Gets a file at path

PUT /api/vfs/{path}
Puts a file at path.

如何在powershell中使用Azure Kudu Rest API你可以参考这个blog。以下是来自博客的sn-p代码

获取 API 授权:

function Get-KuduApiAuthorisationHeaderValue($resourceGroupName, $webAppName){

    $publishingCredentials = Get-PublishingProfileCredentials $resourceGroupName $webAppName

    return ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword))))
}

上传单个文件

function Upload-FileToWebApp($kuduApiAuthorisationToken, $webAppName, $fileName, $localPath ){

    $kuduApiUrl = "https://$webAppName.scm.azurewebsites.net/api/vfs/site/wwwroot/app/resources/$fileName"

    $result = Invoke-RestMethod -Uri $kuduApiUrl `
                        -Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
                        -Method PUT `
                        -InFile $localPath `
                        -ContentType "multipart/form-data"
}

【讨论】:

    猜你喜欢
    • 2021-07-11
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多