Azure 逻辑应用 : how to run Powershell script or Azure CLI?

标签 azure powershell azure-logic-apps azure-cli

我正在构建我的 Azure 逻辑应用工作流程,该工作流程应该检查一些条件并运行以下 Powershell:

Stop-AzureWebsiteJob -Name MyWebsite -JobName MyWebJob
Start-AzureWebsiteJob -Name MyWebsite -JobName MyWebJob -JobType Continuous

问题是:在 Azure 逻辑应用中调用此类脚本的最简单方法是什么? Powershell 似乎没有内置 block /连接器,所以我想知道有哪些可能性。或者,使用类似的操作运行 az CLI 命令可能会更容易

最佳答案

最终我得到了一个利用Azure 自动化的解决方案。从 Azure 门户,我们可以在自动化中创建新的资源类型:

enter image description here

创建资源后,我们可以在 Runbooks 选项卡下添加新的 Runbook:

enter image description here

Runbook 可以运行 Powershell Workflow并使用 AzureRunAsConnection 选项获得授权(详细信息 here )。我的示例 Powershell 应该重新启动特定应用服务的 WebJob,如下所示:

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
}

完成此工作流设置后,我们可以通过向逻辑添加新 block 来从 Azure 逻辑应用运行它。

enter image description here

关于Azure 逻辑应用 : how to run Powershell script or Azure CLI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53414671/

相关文章:

python - 消费计划下的 Azure 逻辑应用程序可以调用具有 VNet 集成的应用程序服务计划下的 azure 函数吗

azure-logic-apps - Azure 函数与逻辑应用

azure - 为什么我们需要两个不同的 Web 作业存储帐户?

java - 使用用户名和密码访问 Azure Active Directory

azure - 将 Polymer 2.0 项目部署到 Microsoft Azure Web 应用程序

sql - 使用 BizTalk 混合连接从 Azure 外部的应用程序连接到本地 SQL

azure - 如何知道PowerShell中是否存在特定字符串?

powershell - 如何从函数返回SecureString对象

azure - 添加自定义主体:property to Azure Logic App Service Bus Property

Azure - PowerShell 如何在重新连接后恢复/重新设置变量值