Das Azure CLI azure resource show
ähnelt Azure PowerShell Get-AzureRmResource
und verwendet immer die "GET" -Methode. Wenn Sie die Option "-vv" hinzufügen, sehen Sie die verwendete REST-API. Auf der anderen Seite verwendet die PowerShell Invoke-AzureRmResourceAction
die "POST" -Methode. Wenn Sie die Option "-debug" zu Invoke-AzureRmResourceAction
hinzufügen, können Sie die REST-API sehen.
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
Hier ist ein Powershell-Skript diese REST API aufzurufen:
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
Wenn Sie unter Linux-System sind, können Sie mit OAuth 2. Das Skript unter bash Sie den Veröffentlichungs Credential curl verwenden können, geben Ihrer Web-App. Aber, um mein Skript zu verwenden, müssen Sie create a service principle und install 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"
Vielen Dank, dass Sie ein detailliertes Beispiel für die Verwendung der REST-API zum Abrufen von Veröffentlichungsdaten angegeben haben. Ich könnte dieses Beispiel definitiv in einem anderen Kontext verwenden. Bis Azure CLI für die Unterstützung von Ressourcen der Stufe 2 festgelegt wurde, muss der Windows-Rechner für Jenkin-Server verwendet und Azure PowerShell verwendet werden. –
Ich habe die Azure CLI überprüft, sie unterstützen Level 2-Ressourcen mit der Option --parent. Es ist jedoch nicht hilfreich für Sie, weil 'azure resource show 'immer die" GET "-Methode verwendet, während Sie in Ihrem Fall die" POST "-Methode verwenden müssen. Ich werde meine Antwort ein wenig aktualisieren. –