【问题标题】:How to use Azure kudu zipdeploy from a Bamboo deployment server如何从 Bamboo 部署服务器使用 Azure kudu zipdeploy
【发布时间】:2018-01-16 07:40:37
【问题描述】:

我正在尝试找到一种方法,使用 PowerShell 从 Bamboo 部署服务器脚本任务将应用服务更新部署到 Azure 应用服务。

我遇到了身份验证部分的问题。

注意:感谢https://markheath.net/post/deploy-azure-webapp-kudu-zip-api 提供脚本创意。

下面是我的 PowerShell 脚本。

$PublishingUsername = ["The value of the userName property name in the Azure PublishSettings file"]

$PublishingPassword = ["The value of the userPWD property name in the Azure PublishSettings file"]

$SlotName = ["The name of the slot. I.e. qa"]

$WebAppName = ["The name of the app service in Azure"]

$LocalPath = ["The location of zip file that holds the VS2017 Publish Output files"]

function Upload-ZipDeploy() {

    $pair = "$($PublishingUsername):$($PublishingPassword)"
    $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
    $basicAuthValue = "Basic $encodedCreds"

    $Headers = @{
        Authorization = $basicAuthValue
    }

    if ($SlotName -eq ""){
        $kuduApiUrl = "https://$WebAppName.scm.azurewebsites.net/api/zipdeploy"
    }
    else{
        $kuduApiUrl = "https://$WebAppName`-$SlotName.scm.azurewebsites.net/api/zipdeploy"
    }

    # use kudu deploy from zip file
    Invoke-WebRequest -Uri $kuduApiUrl -Headers $Headers `
        -InFile $LocalPath -ContentType "multipart/form-data" -Method Post


}

Upload-ZipDeploy

当我运行这个脚本时,我得到了

Invoke-WebRequest : Server Error
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the 
credentials that you supplied.

我正在使用我为 Azure 中的应用服务部署槽设置下载的 *.PublishSettings 文件中的 userName 和 userPWD 值。我可以在 VS2017 的发布向导中导入相同的 *.PublishSettings 文件并成功发布到该插槽。我似乎无法在 PowerShell 中执行此操作。

我在这里错过了什么?

【问题讨论】:

    标签: powershell azure bamboo kudu azure-app-service-envrmnt


    【解决方案1】:

    这里的解决方案相当简单。我使用的是 Microsoft 从 publishSettings 文件中生成的用户名,并且该用户名以 $ 开头。因此,PowerShell 正在剥离 $ 和第一个字符。我在用户名前面加上了一个反引号,这样可以防止用户名被剥离。它现在工作正常。

    我还在 azurewebsites.net 域之后添加了:443,因为这是它在 publishSettings 文件中的显示方式,但我不确定它是否真的需要,因为 url 已经以 https:// 开头。

    【讨论】:

    • 您不需要尾随端口号。您还可以通过将基本身份验证凭据直接传递到 URL 来对 Kudu 进行经过身份验证的调用:https://`$WebAppName:`$PublishingPassword@site.scm.azurewebsites.net/api/zipdeploy
    猜你喜欢
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多