2017-11-28 4 views
-1

Ich versuche, Web-Auftrag in Azure mithilfe von Powershell-Skript bereitzustellen, wo wir unser eigenes Deployment-Framework haben. Wenn ich das Deployment von meinem lokalen Computer aus durchführen möchte, muss ich es nur bereitstellen Administrator- oder Co-Admin-Berechtigungen, wenn das Access-Script des Contributors fehlschlägt. Unser Implementierungsframework hat nur Contributor-Berechtigungen. Gibt es eine Möglichkeit, einen Web-Job mit den Contributor-Berechtigungen bereitzustellen, und ich ARM-Vorlagen für die Web-Job-Bereitstellung nicht gefunden habe Lösungsdatei in lokal. Irgendwelche Vorschläge bitte Hier ist mein SkriptBereitstellen von Web-Jobs mit ARM oder dem Powershell-Skript

`Add-AzureAccount (since web job doesn't have any RM commandlett i am using classic login where All our resource are in RM) 
Select-AzureSubscription -SubscriptionName "*************" 

$packageSource ="$Global:packageDir/../output\deletelogs\bin" 

$destinationSource = "$env:TEMP\DeleteLogsWebjob.zip" 

If(Test-path $destinationSource) {Remove-item $destinationSource} 

Add-Type -assembly "system.io.compression.filesystem" 

[io.compression.zipfile]::CreateFromDirectory($packageSource, $destinationSource) 

$webappname = AzCreateWebAppName "mywebapp$(Get-Random)" 

$location = "EastUs"   #GetCurrentRegion 

$resourceGroupName= "*****"   # AzGetResourceGroup 

$webjobName = $webappname +"_deletelogsjob" 

$jobCollecctionName = $webappname + $webjobName + "JobCollection" 

#<### Defining Schedules 
#$date = Get-Date 
#$startDate = $date.ToString("MM-dd-yyy HH:mm tt") 
#$endDate = $date.AddYears(1).ToString("MM-dd-yyy HH:mm tt")#> 

# #Create an App Service plan in Free tier. 
New-AzureRmAppServicePlan -Name $webappname -Location $location -ResourceGroupName $resourceGroupName -Tier Basic 

## Create a web app. 
$webapp = New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname -ResourceGroupName $resourceGroupName 

###### Create WebJob 

$job = New-AzureWebsiteJob -Name $webapp -JobName $webjobName -JobType Triggered -JobFile $destinationSource 

$jobCollection = New-AzureRmSchedulerJobCollection -Location $location -JobCollectionName $jobCollecctionName -ResourceGroupName $resourceGroupName 

$temp = "$env:TEMP\appsetting.xml" 

$file = Get-AzureRMWebAppPublishingProfile -ResourceGroupName $resourceGroupName -Name $webappname -OutputFile $temp -Format WebDeploy 


$webSitePassword = ([xml]$file).ChildNodes[0].ChildNodes[0].Attributes[5].Value 


$webSiteUserName = ([xml]$file).ChildNodes[0].ChildNodes[0].Attributes[4].Value 

$uri = "https://{0}:{1}@{2}.scm.azurewebsites.net/api/triggeredwebjobs/{3}/run" -f $webSiteUserName, $webSitePassword,$webappname, $webjobName 

New-AzureRmSchedulerHttpJob -ResourceGroupName $resourceGroupName ` 
    -JobCollectionName $jobCollection[0].JobCollectionName -JobName "deleteLogsScheduler" -Method POST ` 
    -URI $uri -StartTime $startDate -Interval 2 -Frequency Minute ` 
    -EndTime $endDate` 
+0

Überprüfen Sie das [Beispiel] (https://github.com/projectkudu/kudu/wiki/Deploying-a-WebJob-using-PowerShell-ARM-Cmdlets)? Sie sollten das ARM-Cmdlet nicht mit ARM und klassischem Cmdlet gemischt verwenden. –

+0

Vielleicht ist das Problem das Verwenden von Arm und Klassik in demselben Code und der Code, den du gabst, hat eine Kudu-Autorisierung, die ich nicht bekomme, wenn du irgendeine Referenz hast, kannst du sie bitte teilen. –

+0

Ich aktualisiere meine Antwort. Sie können dies [Antwort] (https://stackoverflow.com/questions/27443368/azure-websites-kudu-rest-api-authentication) überprüfen. –

Antwort

0

Sie Beispiel in diesem blog nutzen könnten.

#Resource details : 
$resourceGroupName = "<Resourcegroup name>"; 
$webAppName = "<WebApp name>"; 
$Apiversion = 2015-08-01 

#Function to get Publishing credentials for the WebApp : 
function Get-PublishingProfileCredentials($resourceGroupName, $webAppName){ 

$resourceType = "Microsoft.Web/sites/config" 
$resourceName = "$webAppName/publishingcredentials" 
$publishingCredentials = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType 
$resourceType -ResourceName $resourceName -Action list -ApiVersion $Apiversion -Force 
    return $publishingCredentials 
} 

#Pulling authorization access token : 
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)))) 
} 

$accessToken = Get-KuduApiAuthorisationHeaderValue $resourceGroupName $webAppname 
#Generating header to create and publish the Webjob : 
$Header = @{ 
'Content-Disposition'='attachment; attachment; filename=Copy.zip' 
'Authorization'=$accessToken 
     } 
$apiUrl = "https://$webAppName.scm.azurewebsites.net/api/<Webjob-type>/<Webjob-name>" 
$result = Invoke-RestMethod -Uri $apiUrl -Headers $Header -Method put -InFile "<Complete path of the file>\ 
<filename>.zip" -ContentType 'application/zip' 
#NOTE: Update the above script with the parameters highlighted and run in order to push a new Webjob under the specified WebApp. 

Für Kudu Genehmigung

$ creds = Invoke-AzureRmResourceAction -ResourceGroupName YourResourceGroup -ResourceType Microsoft.Web/sites/config -ResourceName YourWebApp/publishingcredentials -Action Liste -ApiVersion 2015.08.01 -Force

$username = $creds.Properties.PublishingUserName 
$password = $creds.Properties.PublishingPassword 
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password))) 

$apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api" 

$kuduVersion = Invoke-RestMethod -Uri "$apiBaseUrl/environment" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET 
Verwandte Themen