Azure 逻辑应用中工作流定义语言的架构引用指南Schema reference guide for the Workflow Definition Language in Azure Logic Apps

Azure 逻辑应用中创建逻辑应用时,该逻辑应用会采用一个基础工作流定义,其中描述了在逻辑应用中运行的实际逻辑。When you create a logic app in Azure Logic Apps, your logic app has an underlying workflow definition that describes the actual logic that runs in your logic app. 该工作流定义使用 JSON,并遵循工作流定义语言架构验证的结构。That workflow definition uses JSON and follows a structure that's validated by the Workflow Definition Language schema. 本参考文档将会概述此结构,并介绍该架构如何定义工作流定义中的特征。This reference provides an overview about this structure and how the schema defines attributes in your workflow definition.

工作流定义结构Workflow definition structure

工作流定义始终包含一个用于实例化逻辑应用的触发器,以及该触发器激发后要运行的一个或多个操作。A workflow definition always includes a trigger for instantiating your logic app, plus one or more actions that run after the trigger fires.

下面是工作流定义的高级结构:Here is the high-level structure for a workflow definition:

"definition": {
  "$schema": "<workflow-definition-language-schema-version>",
  "actions": { "<workflow-action-definitions>" },
  "contentVersion": "<workflow-definition-version-number>",
  "outputs": { "<workflow-output-definitions>" },
  "parameters": { "<workflow-parameter-definitions>" },
  "staticResults": { "<static-results-definitions>" },
  "triggers": { "<workflow-trigger-definitions>" }
}
属性Attribute 必须Required 说明Description
definition Yes 工作流定义的起始元素The starting element for your workflow definition
$schema 仅当在外部引用工作流定义时才使用Only when externally referencing a workflow definition 描述工作流定义语言版本的 JSON 架构文件的位置。可在以下位置找到该文件:The location for the JSON schema file that describes the Workflow Definition Language version, which you can find here:

https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json

actions No 要在工作流运行时执行的一个或多个操作的定义。The definitions for one or more actions to execute at workflow runtime. 有关详细信息,请参阅触发器和操作For more information, see Triggers and actions.

操作数量上限:250Maximum actions: 250

contentVersion No 工作流定义的版本号,默认为“1.0.0.0”。The version number for your workflow definition, which is "1.0.0.0" by default. 为了帮助在部署工作流时识别并确认正确的定义,请指定要使用的值。To help identify and confirm the correct definition when deploying a workflow, specify a value to use.
outputs No 从工作流运行返回的输出的定义。The definitions for the outputs to return from a workflow run. 有关详细信息,请参阅输出For more information, see Outputs.

输出数量上限:10 个Maximum outputs: 10

parameters No 一个或多个参数的定义,这些参数传递的值用于逻辑应用的运行时。The definitions for one or more parameters that pass the values to use at your logic app's runtime. 有关详细信息,请参阅参数For more information, see Parameters.

参数数量上限:50Maximum parameters: 50

staticResults No 对操作启用静态结果时,这些操作作为模拟输出返回的一个或多个静态结果的定义。The definitions for one or more static results returned by actions as mock outputs when static results are enabled on those actions. 在每个操作定义中,runtimeConfiguration.staticResult.name 特征引用 staticResults 中的相应定义。In each action definition, the runtimeConfiguration.staticResult.name attribute references the corresponding definition inside staticResults. 有关详细信息,请参阅静态结果For more information, see Static results.
triggers No 用于实例化工作流的一个或多个触发器的定义The definitions for one or more triggers that instantiate your workflow. 可以定义多个触发器,但只能使用工作流定义语言来定义,而不能通过逻辑应用设计器以可视方式进行定义。You can define more than one trigger, but only with the Workflow Definition Language, not visually through the Logic Apps Designer. 有关详细信息,请参阅触发器和操作For more information, see Triggers and actions.

触发器数量上限:10 个Maximum triggers: 10

触发器和操作Triggers and actions

在工作流定义中,triggersactions 节定义工作流执行期间发生的调用。In a workflow definition, the triggers and actions sections define the calls that happen during your workflow's execution. 有关这些节的语法和详细信息,请参阅工作流触发器和操作For syntax and more information about these sections, see Workflow triggers and actions.

parametersParameters

部署生命周期通常有用于开发、测试、过渡和生产的不同环境。The deployment lifecycle usually has different environments for development, test, staging, and production. 将逻辑应用部署到各种环境时,可能需要根据部署需求使用不同的值,例如连接字符串。When deploying logic apps to various environments, you likely want to use different values, such as connection strings, based on your deployment needs. 或者,你可能希望在整个逻辑应用中重用某些值而无需进行硬编码,或者你的某些值经常更改。Or, you might have values that you want to reuse throughout your logic app without hardcoding or that change often. 在工作流定义的 parameters 节中,可以为逻辑应用在运行时使用的值定义或编辑参数。In your workflow definition's parameters section, you can define or edit parameters for the values that your logic app uses at runtime. 你必须先定义这些参数,然后才能在工作流定义中的其他位置引用这些参数。You must define these parameters first before you can reference these parameters elsewhere in your workflow definition.

下面是参数定义的一般结构:Here is the general structure for a parameter definition:

"parameters": {
   "<parameter-name>": {
      "type": "<parameter-type>",
      "defaultValue": <default-parameter-value>,
      "allowedValues": [ <array-with-permitted-parameter-values> ],
      "metadata": {
         "description": "<parameter-description>"
      }
   }
},
属性Attribute 必须Required 类型Type 说明Description
<parameter-name><parameter-name> Yes StringString 要定义的参数的名称The name for the parameter that you want to define
<parameter-type><parameter-type> Yes int、float、string、bool、array、object、securestring、secureobjectint, float, string, bool, array, object, securestring, secureobject

注意:对于所有密码、密钥和机密,请使用 securestringsecureobject 类型,因为 GET 操作不会返回这些类型。Note: For all passwords, keys, and secrets, use the securestring or secureobject types because the GET operation doesn't return these types. 若要详细了解如何保护参数,请参阅操作和输入参数的安全建议For more information about securing parameters, see Security recommendations for action and input parameters.

参数的类型The type for the parameter
<default-parameter-value><default-parameter-value> Yes type 相同Same as type 在工作流实例化时未指定值的情况下使用的默认参数值。The default parameter value to use if no value is specified when the workflow instantiates. defaultValue 属性是逻辑应用设计器正确显示参数所必需的,但是你可以指定空值。The defaultValue attribute is required so that the Logic App Designer can correctly show the parameter, but you can specify an empty value.
<array-with-permitted-parameter-values><array-with-permitted-parameter-values> No ArrayArray 包含参数可接受的值的数组An array with values that the parameter can accept
<parameter-description><parameter-description> No JSON 对象JSON object 任何其他的参数详细信息,例如参数的说明Any other parameter details, such as a description for the parameter

接下来,请为工作流定义创建一个 Azure 资源管理器模板,定义模板参数来接收部署时需要的值,视情况将硬编码值替换为对模板或工作流定义参数的引用,并将需要在部署时使用的值存储在单独的参数文件中。Next, create an Azure Resource Manager template for your workflow definition, define template parameters that accept the values you want at deployment, replace hardcoded values with references to template or workflow definition parameters as appropriate, and store the values to use at deployment in a separate parameter file. 这样,无需更新和重新部署逻辑应用即可通过参数文件更轻松地更改这些值。That way, you can change those values more easily through the parameter file without having to update and redeploy your logic app. 对于敏感的或者必须进行保护的信息(例如用户名、密码和机密),可将这些值存储在 Azure Key Vault 中,让参数文件从密钥保管库中检索这些值。For information that is sensitive or must be secured, such as usernames, passwords, and secrets, you can store those values in Azure Key Vault and have your parameter file retrieve those values from your key vault. 若要通过示例详细了解如何在模板和工作流定义级别定义参数,请参阅概览:使用 Azure 资源管理器模板将逻辑应用部署自动化For more information and examples about defining parameters at the template and workflow definition levels, see Overview: Automate deployment for logic apps with Azure Resource Manager templates.

静态结果Static results

staticResults 特性中,定义操作的模拟 outputsstatus,启用操作的静态结果设置时,操作将返回这些信息。In the staticResults attribute, define an action's mock outputs and status that the action returns when the action's static result setting is turned on. 在操作的定义中,runtimeConfiguration.staticResult.name 特性引用 staticResults 中的静态结果定义的名称。In the action's definition, the runtimeConfiguration.staticResult.name attribute references the name for the static result definition inside staticResults. 了解如何通过设置静态结果来使用模拟数据测试逻辑应用Learn how you can test logic apps with mock data by setting up static results.

"definition": {
   "$schema": "<...>",
   "actions": { "<...>" },
   "contentVersion": "<...>",
   "outputs": { "<...>" },
   "parameters": { "<...>" },
   "staticResults": {
      "<static-result-definition-name>": {
         "outputs": {
            <output-attributes-and-values-returned>,
            "headers": { <header-values> },
            "statusCode": "<status-code-returned>"
         },
         "status": "<action-status>"
      }
   },
   "triggers": { "<...>" }
}
属性Attribute 必须Required 类型Type 说明Description
<static-result-definition-name><static-result-definition-name> Yes StringString 操作定义可通过 runtimeConfiguration.staticResult 对象引用的静态结果定义的名称。The name for a static result definition that an action definition can reference through a runtimeConfiguration.staticResult object. 有关详细信息,请参阅运行时配置设置For more information, see Runtime configuration settings.

可以使用所需的任意唯一名称。You can use any unique name that you want. 默认情况下,此唯一名称的后面会追加一个按需递增的数字。By default, this unique name is appended with a number, which is incremented as necessary.

<output-attributes-and-values-returned><output-attributes-and-values-returned> Yes 多种多样Varies 这些特性的要求因条件不同而异。The requirements for these attributes vary based on different conditions. 例如,如果 statusSucceeded,则 outputs 特性包含操作作为模拟输出返回的特性和值。For example, when the status is Succeeded, the outputs attribute includes attributes and values returned as mock outputs by the action. 如果 statusFailed,则 outputs 特性包含 errors 特性,即提供错误信息的一个或多个错误 message 对象的数组。If the status is Failed, the outputs attribute includes the errors attribute, which is an array with one or more error message objects that have error information.
<header-values><header-values> No JSONJSON 操作返回的任何标头值Any header values returned by the action
<status-code-returned><status-code-returned> Yes StringString 操作返回的状态代码The status code returned by the action
<action-status><action-status> Yes StringString 操作的状态,例如 SucceededFailedThe action's status, for example, Succeeded or Failed

例如,在此 HTTP 操作定义中,runtimeConfiguration.staticResult.name 特性引用 staticResults 中的定义了操作模拟输出的 HTTP0 特性。For example, in this HTTP action definition, the runtimeConfiguration.staticResult.name attribute references HTTP0 inside the staticResults attribute where the mock outputs for the action are defined. runtimeConfiguration.staticResult.staticResultOptions 特性指定 HTTP 操作的静态结果设置为 EnabledThe runtimeConfiguration.staticResult.staticResultOptions attribute specifies that the static result setting is Enabled on the HTTP action.

"actions": {
   "HTTP": {
      "inputs": {
         "method": "GET",
         "uri": "https://www.microsoft.com"
      },
      "runAfter": {},
      "runtimeConfiguration": {
         "staticResult": {
            "name": "HTTP0",
            "staticResultOptions": "Enabled"
         }
      },
      "type": "Http"
   }
},

HTTP 操作在 staticResults 内的 HTTP0 定义中返回输出。The HTTP action returns the outputs in the HTTP0 definition inside staticResults. 在此示例中,状态代码的模拟输出为 OKIn this example, for the status code, the mock output is OK. 标头值的模拟输出为 "Content-Type": "application/JSON"For header values, the mock output is "Content-Type": "application/JSON". 操作状态的模拟输出为 SucceededFor the action's status, the mock output is Succeeded.

"definition": {
   "$schema": "<...>",
   "actions": { "<...>" },
   "contentVersion": "<...>",
   "outputs": { "<...>" },
   "parameters": { "<...>" },
   "staticResults": {
      "HTTP0": {
         "outputs": {
            "headers": {
               "Content-Type": "application/JSON"
            },
            "statusCode": "OK"
         },
         "status": "Succeeded"
      }
   },
   "triggers": { "<...>" }
},

表达式Expressions

使用 JSON 可以获取设计时存在的文本值,例如:With JSON, you can have literal values that exist at design time, for example:

"customerName": "Sophia Owen", 
"rainbowColors": ["red", "orange", "yellow", "green", "blue", "indigo", "violet"], 
"rainbowColorsCount": 7 

还可以获取在运行时之前不存在的值。You can also have values that don't exist until run time. 若要表示这些值,可以使用运行时计算的表达式。To represent these values, you can use expressions, which are evaluated at run time. 表达式是可以包含一个或多个函数运算符变量、显式值或常量的序列。An expression is a sequence that can contain one or more functions, operators, variables, explicit values, or constants. 在工作流定义中,可以在 JSON 字符串值中的任何位置使用表达式,只需为表达式加上 @ 符号前缀即可。In your workflow definition, you can use an expression anywhere in a JSON string value by prefixing the expression with the at-sign (@). 计算表示 JSON 值的表达式时,会通过删除 @ 字符来提取表达式主体,并且始终生成另一个 JSON 值。When evaluating an expression that represents a JSON value, the expression body is extracted by removing the @ character, and always results in another JSON value.

例如,对于前面定义的 customerName 属性,可以通过在表达式中使用 parameters() 函数来获取属性值,并将该值分配给 accountName 属性:For example, for the previously defined customerName property, you can get the property value by using the parameters() function in an expression and assign that value to the accountName property:

"customerName": "Sophia Owen",
"accountName": "@parameters('customerName')"

字符串内插还允许在字符串中使用由 @ 字符和大括号 ({}) 包装的多个表达式。String interpolation also lets you use multiple expressions inside strings that are wrapped by the @ character and curly braces ({}). 语法如下:Here is the syntax:

@{ "<expression1>", "<expression2>" }

结果始终是一个字符串。因此,此功能类似于 concat() 函数,例如:The result is always a string, making this capability similar to the concat() function, for example:

"customerName": "First name: @{parameters('firstName')} Last name: @{parameters('lastName')}"

如果某个文本字符串以 @ 字符开头,请加上 @ 字符作为前缀,并加上另一个 @ 字符作为转义符:@@If you have a literal string that starts with the @ character, prefix the @ character with another @ character as an escape character: @@

这些示例演示如何计算表达式:These examples show how expressions are evaluated:

JSON 值JSON value 结果Result
"Sophia Owen""Sophia Owen" 返回这些字符:“Sophia Owen”Return these characters: 'Sophia Owen'
"array[1]""array[1]" 返回这些字符:'array[1]'Return these characters: 'array[1]'
"@@""@@" 以单字符字符串的形式返回这些字符:'@'Return these characters as a one-character string: '@'
" @"" @" 以双字符字符串的形式返回这些字符:' @'Return these characters as a two-character string: ' @'

这些示例假设定义了 "myBirthMonth" 等于 "January","myAge" 等于数字 42:For these examples, suppose you define "myBirthMonth" equal to "January" and "myAge" equal to the number 42:

"myBirthMonth": "January",
"myAge": 42

这些示例演示如何计算以下表达式:These examples show how the following expressions are evaluated:

JSON 表达式JSON expression 结果Result
"@parameters('myBirthMonth')""@parameters('myBirthMonth')" 返回此字符串:“January”Return this string: "January"
"@{parameters('myBirthMonth')}""@{parameters('myBirthMonth')}" 返回此字符串:“January”Return this string: "January"
"@parameters('myAge')""@parameters('myAge')" 返回此数字:42Return this number: 42
"@{parameters('myAge')}""@{parameters('myAge')}" 以字符串形式返回此数字:“42”Return this number as a string: "42"
"My age is @{parameters('myAge')}""My age is @{parameters('myAge')}" 返回此字符串:“My age is 42”Return this string: "My age is 42"
"@concat('我的年龄是 ', string(parameters('myAge')))""@concat('My age is ', string(parameters('myAge')))" 返回此字符串:“My age is 42”Return this string: "My age is 42"
"My age is @@{parameters('myAge')}""My age is @@{parameters('myAge')}" 返回此字符串,其中包括表达式:“My age is @{parameters('myAge')}`Return this string, which includes the expression: "My age is @{parameters('myAge')}`

在逻辑应用设计器中以可视方式操作时,可以通过表达式生成器创建表达式,例如:When you're working visually in the Logic Apps Designer, you can create expressions through the Expression builder, for example:

逻辑应用设计器 > 表达式生成器

完成后,将为工作流定义中的相应属性显示表达式,例如,下面的 searchQuery 属性:When you're done, the expression appears for the corresponding property in your workflow definition, for example, the searchQuery property here:

"Search_tweets": {
  "inputs": {
    "host": {
      "connection": {
        "name": "@parameters('$connections')['twitter']['connectionId']"
      }
    }
  },
  "method": "get",
  "path": "/searchtweets",
  "queries": {
    "maxResults": 20,
    "searchQuery": "Azure @{concat('firstName','', 'LastName')}"
  }
},

OutputsOutputs

outputs 节中,定义工作流在完成运行时可以返回的数据。In the outputs section, define the data that your workflow can return when finished running. 例如,若要跟踪每次运行的特定状态或值,请指定工作流输出应返回该数据。For example, to track a specific status or value from each run, specify that the workflow output returns that data.

备注

在响应来自服务 REST API 的传入请求时,请不要使用 outputsWhen responding to incoming requests from a service's REST API, do not use outputs. 请改用 Response 操作类型。Instead, use the Response action type. 有关详细信息,请参阅工作流触发器和操作For more information, see Workflow triggers and actions.

下面是输出定义的一般结构:Here is the general structure for an output definition:

"outputs": {
  "<key-name>": {
    "type": "<key-type>",
    "value": "<key-value>"
  }
}
属性Attribute 必须Required 类型Type 说明Description
<key-name><key-name> Yes StringString 输出返回值的密钥名称The key name for the output return value
<key-type><key-type> Yes int、float、string、securestring、bool、array、JSON 对象int, float, string, securestring, bool, array, JSON object 输出返回值的类型The type for the output return value
<key-value><key-value> Yes 与 <key-type> 相同Same as <key-type> 输出返回值The output return value

若要从工作流运行中获取输出,请在 Azure 门户中查看逻辑应用的运行历史记录和详细信息,或使用工作流 REST APITo get the output from a workflow run, review your logic app's run history and details in the Azure portal or use the Workflow REST API. 也可将输出传递给 Power BI 等外部系统,以便可创建仪表板。You can also pass output to external systems, for example, Power BI so that you can create dashboards.

运算符Operators

表达式函数中,运算符执行特定的任务,例如,引用数组中的某个属性或值。In expressions and functions, operators perform specific tasks, such as reference a property or a value in an array.

运算符Operator 任务Task
'' 若要使用字符串文本作为输入,或者在表达式和函数中使用字符串文本,请仅使用单引号包装该字符串,例如 '<myString>'To use a string literal as input or in expressions and functions, wrap the string only with single quotation marks, for example, '<myString>'. 不要使用双引号 (""),否则与整个表达式两侧的 JSON 格式相冲突。Do not use double quotation marks (""), which conflict with the JSON formatting around an entire expression. 例如:For example:

正确:length('Hello')Yes: length('Hello')
错误:length("Hello")No: length("Hello")

如果传递数组或数字,则不需要包装标点符号。When you pass arrays or numbers, you don't need wrapping punctuation. 例如:For example:

正确:length([1, 2, 3])Yes: length([1, 2, 3])
错误:length("[1, 2, 3]")No: length("[1, 2, 3]")

[][] 若要引用数组中特定位置(索引)处的某个值,请使用方括号。To reference a value at a specific position (index) in an array, use square brackets. 例如,若要获取数组中的第二个项:For example, to get the second item in an array:

myArray[1]

上获取。. 若要引用对象中的属性,请使用点运算符。To reference a property in an object, use the dot operator. 例如,若要获取 customer JSON 对象的 name 属性:For example, to get the name property for a customer JSON object:

"@parameters('customer').name"

?? 若要引用未发生运行时错误的对象中的 null 属性,请使用问号运算符。To reference null properties in an object without a runtime error, use the question mark operator. 例如,若要处理触发器中的 null 输出,可使用以下表达式:For example, to handle null outputs from a trigger, you can use this expression:

@coalesce(trigger().outputs?.body?.<someProperty>, '<property-default-value>')

函数Functions

某些表达式从运行时操作获取其值,而这些操作在工作流定义开始运行时可能不存在。Some expressions get their values from runtime actions that might not yet exist when your workflow definition starts to run. 若要在表达式中引用或处理这些值,可以使用工作流定义语言提供的函数To reference or work with these values in expressions, you can use functions that the Workflow Definition Language provides.

后续步骤Next steps