2017-12-19 15 views
1

PowerShellを使用してBambooデプロイメントサーバーのスクリプトタスクからAzureアプリケーションサービスにアプリケーションサービスの更新を展開する方法を見つけようとしています。BambooデプロイメントサーバーからAzure kudu zipdeployを使用する方法

認証部分に問題が発生しています。

注:スクリプトのアイデアは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. 

を取得し、私は* .PublishSettingsからユーザー名とuserPWD値を使用しています、私はアズールでのアプリのサービス展開スロットの設定のためにダウンロードしたファイル。 VS2017のパブリッシュウィザードで同じ* .PublishSettingsファイルをインポートして、そのスロットに正常にパブリッシュできます。私はPowerShellでやっているようではありません。

私はここで何が欠けていますか?

答えて

1

ここの解決法はかなり簡単でした。私はpublishSettingsファイルからMicrosoftが生成したユーザー名を使用していましたが、そのユーザー名は$で始まりました。したがって、PowerShellは$と最初の文字を削除していました。ユーザー名の前にバックティックが付いていたので、ユーザー名は削除されませんでした。今は正しく動作しています。

azurewebsites.netドメインの後ろに:443が追加されています。これはpublishSettingsファイルに表示される方法ですが、URLがhttps://で始まっているため実際には必要ないかどうかはわかりません。

+0

後続のポート番号は必要ありません。基本認証認証情報をURLに直接渡すことで、Kuduに対して認証された呼び出しを行うこともできます: 'https:// \' $ WebAppName:\ '$ PublishingPassword @ site.scm.azurewebsites.net/api/zipdeploy' – evilSnobu

関連する問題