【问题标题】:How can I get the workflow definition of a logic app as JSON?如何将逻辑应用的工作流定义获取为 JSON?
【发布时间】:2019-12-13 23:53:17
【问题描述】:

如何以 JSON 格式获取逻辑应用的工作流定义?

我可以使用New-AzLogicApp 命令从 JSON 定义文件创建新的逻辑应用

但我看不到如何反转该过程,即获取现有逻辑应用的 JSON 定义。

我尝试了Get-AzLogicApp,它返回一个Workflow 对象。

但我在最后一步被阻止了,即从工作流返回到实际的 JSON 文件

【问题讨论】:

  • 抱歉,工作优先级阻碍了我……我的待办事项清单上确实有它
  • 好吧,其实测试只需要一分钟。;-)

标签: powershell azure-logic-apps


【解决方案1】:

您可以使用REST API 获取详细信息。

REST API Documentation

或者您可以尝试使用Get-AzLogicApp | ConvertFrom-Json | ConvertTo-Json 看看是否有帮助

【讨论】:

  • 第二个选项失败并出现错误... ConvertFrom-Json : Invalid JSON primitive: Microsoft.Azure.Management.Logic.Models.Workflow。
【解决方案2】:

如果您想获取逻辑应用的定义,请尝试以下命令。

$logicapp = Get-AzResource -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Logic/workflows -ResourceName "<logic app name>"
$logicapp.properties.definition | ConvertTo-Json

如果您想将其作为.json 文件获取,只需将第二行更改如下。

$logicapp.properties.definition | ConvertTo-Json | Out-File "C:\Users\joyw\Desktop\logic.json" 

更新:

您可以将ConvertTo-Json -Depth 参数指定为3,如果您希望在JSON 表示中包含更多级别的包含对象,您也可以使用其他值指定它。

-深度

指定在 JSON 表示中包含多少级别的包含对象。默认值为 2。

$logicapp.properties.definition | ConvertTo-Json -Depth 3

【讨论】:

  • 工作,但不是 100% ... runAfter 值设置为例如"runAfter": "@{Create_blob=System.Object[]}",
  • 什么时候应该... "runAfter": { "Create_blob": [ "Succeeded" ] },
【解决方案3】:

我已经深入了解了客户中的一个项目,您需要这样做:

1 )Get-AzLogicApp 
$lapp.Definition.ToString()-> this is the entire definition of the logicapp
2) Save the definition to a file
3) Use New-AzLogicApp or Set-AzLogicApp with -DefinitionFilePath pointing to that file  

$a= New-AzLogicApp -ResourceGroupName $rg -name $name1 -location $loc -DefinitionFilePath  $fileName1 -ParameterFilePath $parm1
$a.Parameters.Count


*for Parameters i use this content in a file
{
    "$connections": {
        "value": {
            "office365": {
                "connectionId": "/subscriptions/SUBS-DEPLOY/resourceGroups/RG-DEPLOY/providers/Microsoft.Web/connections/office365",
                "connectionName": "office365",
                "id": "/subscriptions/SUBS-DEPLOY/providers/Microsoft.Web/locations/westeurope/managedApis/office365"
            },
            "sharepointonline": {
                "connectionId": "/subscriptions/SUBS-DEPLOY/resourceGroups/RG-DEPLOY/providers/Microsoft.Web/connections/sharepointonline",
                "connectionName": "sharepointonline",
                "id": "/subscriptions/SUBS-DEPLOY/providers/Microsoft.Web/locations/westeurope/managedApis/sharepointonline"
            }
        }
    }
}
replace SUBS-DEPLOY with the subscription id and RG-DEPLOY with resource group name and all good.

Anything just buzz: stationsolutions_at_gmail.com

Hope it helps







Here's the code ..


function Get-LogicApp($resourceGroupName ,$location,$name)
{
    Write-Host " Get LogicApp Definition $name"
    $lapp = Get-AzLogicApp -ResourceGroupName $resourceGroupName -Name $name
    $o= $lapp.Definition.ToString()
    $fileName = "..\logicapps\" + $name + ".logicapp.json"
    $o | Out-File -FilePath $fileName
    $parms = "..\logicapps\templates\parms.json"
    $fileName = "..\logicapps\" + $name + ".logicapp.parms.json"
    Copy-Item -Path $parms  $fileName
    Write-Host " LogicApp Definition $resourceGroupName > $fileName"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 2021-07-05
    • 2017-08-28
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多