Azure Logic Apps: how to run Powershell script or Azure CLI?

前端 未结 3 1518
谎友^
谎友^ 2020-12-20 02:29

I\'m building my Azure Logic Apps worklow which is supposed to check some conditions and run following Powershell:

Stop-AzureWebsiteJob -Name MyWebsite -JobN         


        
3条回答
  •  心在旅途
    2020-12-20 02:33

    Finally I ended up with a solution which takes advantage of Azure Automation. From Azure Portal we can create new Resource typing in Automation:

    Once the resource is created we can add new Runbook under runbooks tab:

    Runbook can run Powershell Workflow and get authorized using AzureRunAsConnection option (details here). My sample Powershell which is supposed to restart WebJob an specific App Service looks like below:

    Workflow RestartMyWebJob
    {
        $Conn = Get-AutomationConnection -Name AzureRunAsConnection
        Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
    
        $AzureContext = Select-AzureRmSubscription -SubscriptionId $Conn.SubscriptionID
    
        $Apiversion = "2015-08-01"
        $ResourceGroupName = 'My-Resource-Group-Name'
        $ResourceName = 'My-Resource-Group-Name/My-AppService--WebJob-Name'
    
    
        Invoke-AzureRmResourceAction -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName $ResourceName -Action stop -ApiVersion $Apiversion -Force
        Invoke-AzureRmResourceAction -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName $ResourceName -Action start -ApiVersion $Apiversion -Force
    }
    

    Having this Workflow setup we can run it from Azure Logic Apps by adding new block to our logic.

提交回复
热议问题