2016-05-10 8 views
0

ARMテンプレートを使用してJavaアプリケーションサービスを作成するプロセスを自動化し、FTP公開メソッドを使用してTomcatのJava WARファイルをアップロードしようとしています。ARMテンプレートを使用して新しく作成/更新されたappserviceにAzure CLIを使用する方法

AzureのCLIでは動作しません後 -

$ azure resource show <resource-group> <appservice-name>/publishingcredentials Microsoft.Web/sites/config 2015-08-01 

error: The resource type could not be found in the namespace 'Microsoft.Web' for api version '2015-08-01' 

しかし、これは、AzureのPowerShellで動作します -

$resource = Invoke-AzureRmResourceAction -ResourceGroupName <resource-group> -ResourceType Microsoft.Web/sites/config -ResourceName <appservice-name>/publishingcredentials -Action list -ApiVersion 2015-08-01 -Force 
$resource.Properties 

私はリソースエクスプローラhttps://resources.azure.comから名前空間を参照するが、右を見つけることができませんされています私は後でスクリプトでWARファイルをアップロードするために使用できるFTPのユーザー名とパスワードを取得するための構文です。

答えて

1

代わりが見つかりました。

手動でリソースグループを作成し、リソースグループの下にあるWebサイトのFTP公開資格情報を手動で設定した場合。次に、リソースグループの代替FTP資格情報を設定します。これは、どのWebサイトにも固有ではありません(またはアカウント全体でグローバルになる可能性があります)。

作成された各Webサイトは、FTPサーバー上で別のドメインを設定し、代替資格情報はftp:///[email protected]の任意のWebサイトで使用できます。

同じリソースグループのgitブランチ名に基づいて新しいsiteNameを作成すると、新しいsiteNameに上記の事前設定されたFTP資格情報を使用してアプリケーションアーカイブをアップロードすることができます。

Azure CLIを使用して、少なくとも代替の資格情報を取得する方法があればいいと思います。リソースエクスプローラは、https://management.azure.com/providers/Microsoft.Web/publishingUsers/web?api-version=2015-08-01の下にそれを示します。

また、ARMテンプレートの "siteConfig"プロパティを設定して、publishingUsernameとpublishingPasswordを設定することもできます。私はこのオプションを試しましたが、これらのプロパティは無視されます。

0

Azure CLI azure resource showは、Azure PowerShell Get-AzureRmResourceに似ており、常に「GET」メソッドを使用しています。 "-vv"オプションを追加すると、使用しているREST APIが表示されます。一方、PowerShell Invoke-AzureRmResourceActionは "POST"メソッドを使用しています。 Invoke-AzureRmResourceActionに '-debug'オプションを追加すると、REST APIを見ることができます。ここで

https://management.azure.com/subscriptions/<your subscription id>/resourceGroups/<resource group>/providers/Microsoft.Web/sites/<app service>/config/publishingcredentials/list?api-version=2015-08-01 

はこのREST APIを呼び出すためのPowerShellスクリプトです:

Add-Type -Path 'C:\Program Files\Microsoft Azure Active Directory Connect\Microsoft.IdentityModel.Clients.ActiveDirectory.dll' 

# The tenant ID of you Subscription. You can use tenant name instead. 
$tenantID = "<the tenant ID of your Subscription>" 

# You can leave the variables as what they are, if you are under Azure Cloud Environment. 
$loginEndpoint = "https://login.windows.net/" 
$managementResourceURI = "https://management.core.windows.net/" 
$redirectURI = New-Object System.Uri ("urn:ietf:wg:oauth:2.0:oob") 
$clientID = "1950a258-227b-4e31-a9cf-717495945fc2" 

# Fill in the below variables. 
$subscriptionID = "<your subscription id>" 
$resouceGroup = "<your resource group>" 
$appService = "<your app service>" 
$username = "<your Azure account>" 


# Constructing the authentication string. 
$authString = $loginEndpoint + $tenantID 

# Use the above authentication string to create an authentication context. 
$authenticationContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext ($authString, $false) 

$promptBehaviour = [Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Auto 

$userIdentifierType = [Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifierType]::RequiredDisplayableId 

$userIdentifier = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier ($username, $userIdentifierType) 


# Prompt for signing in. 
$authenticationResult = $authenticationContext.AcquireToken($managementResourceURI, $clientID, $redirectURI, $promptBehaviour, $userIdentifier); 

# construct authorization header for the REST API. 
$authHeader = $authenticationResult.AccessTokenType + " " + $authenticationResult.AccessToken 
$headers = @{"Authorization"=$authHeader; "Content-Type"="application/json"} 

# Invoke the REST API. 
Invoke-RestMethod -Method POST -Uri "https://management.azure.com/subscriptions/$subscriptionID/resourceGroups/$resourceGroup/providers/Microsoft.Web/sites/$appService/config/publishingcredentials/list?api-version=2015-08-01" ` 
        -Headers $headers 

あなたがLinuxシステムの下にある場合、あなたはあなたの出版資格を与えるbashスクリプト以下のOAuth 2.ザ・とカール使用することができますあなたのウェブアプリのしかし、私のスクリプトを使用するには、create a service principleinstall curl in you Linux systemが必要です。

#!/bin/bash 

tenantID="<the tenant id of your subscription>" 

client_id="<the client id of your AD application>" 

client_secret="<a key you added to your AD application>" 

body="grant_type=client_credentials&client_id=$client_id&client_secret=$client_secret&resource=https%3A%2F%2Fmanagement.core.windows.net%2F" 

authorization=$(curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --data-ascii "$body" "https://login.microsoftonline.com/$tenantID/oauth2/token" | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["token_type"]+" "+obj["access_token"])') 


subscriptionID="<your subscription id>" 
resourceGroup="<the resource group of you web app>" 
appService="<your web app>" 

curl -X POST -H "Authorization: $authorization" --data-ascii "" "https://management.azure.com/subscriptions/$subscriptionID/resourceGroups/$resourceGroup/providers/Microsoft.Web/sites/$appService/config/publishingcredentials/list?api-version=2015-08-01" 
+0

REST APIを使用してpublishingcredentialsを取得する詳細な例を提供していただきありがとうございます。他の文脈でこの例を使用することは間違いありません。 Azure CLIがレベル2のリソースをサポートするように修正されるまでは、Jenkinサーバー用にWindowsマシンを使用し、Azure PowerShellを使用する必要があります。 –

+0

私はAzure CLIをチェックしましたが、実際には '--parent'オプションでレベル2リソースをサポートしています。しかし、 'azure resource show'は常に" GET "メソッドを使用しているので、あなたの場合は助けにならないのですが、あなたの場合は" POST "メソッドを使用する必要があります。私は少し私の答えを更新します。 –

関連する問題