你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
在 Azure 逻辑应用中创建逻辑应用时,该逻辑应用会采用一个基础工作流定义,其中描述了在逻辑应用中运行的实际逻辑。 That workflow definition uses JSON and follows a structure that's validated by the Workflow Definition Language schema. 本参考文档将会概述此结构,并介绍该架构如何定义工作流定义中的特征。
工作流定义结构
工作流定义始终包含一个用于实例化逻辑应用的触发器,以及该触发器激发后要运行的一个或多个操作。
下面是工作流定义的高级结构:
"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 | 工作流定义的起始元素 |
$schema |
仅当在外部引用工作流定义时才使用 | 描述工作流定义语言版本的 JSON 架构文件的位置。可在以下位置找到该文件:https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json |
actions |
No | 要在工作流运行时执行的一个或多个操作的定义。 有关详细信息,请参阅触发器和操作。 操作数目上限:250 |
contentVersion |
No | 工作流定义的版本号,默认为“1.0.0.0”。 为了帮助在部署工作流时识别并确认正确的定义,请指定要使用的值。 |
outputs |
No | 从工作流运行返回的输出的定义。 For more information, see Outputs. 输出数目上限:10 |
parameters |
No | 一个或多个参数的定义,这些参数传递的值用于逻辑应用的运行时。 For more information, see Parameters. 参数数目上限:50 |
staticResults |
No | 对操作启用静态结果时,这些操作作为模拟输出返回的一个或多个静态结果的定义。 在每个操作定义中,runtimeConfiguration.staticResult.name 特征引用 staticResults 中的相应定义。 For more information, see Static results. |
triggers |
No | 用于实例化工作流的一个或多个触发器的定义 可以定义多个触发器,但只能使用工作流定义语言来定义,而不能通过工作流设计器以可视方式进行定义。 有关详细信息,请参阅触发器和操作。 触发器数目上限:10 |
触发器和操作
在工作流定义中,triggers
和 actions
节定义工作流执行期间发生的调用。 有关这些节的语法和详细信息,请参阅工作流触发器和操作。
Parameters
部署生命周期通常有用于开发、测试、过渡和生产的不同环境。 将逻辑应用部署到各种环境时,可能需要根据部署需求使用不同的值,例如连接字符串。 或者,你可能希望在整个逻辑应用中重用某些值而无需进行硬编码,或者你的某些值经常更改。 在工作流定义的 parameters
节中,可以为逻辑应用在运行时使用的值定义或编辑参数。 你必须先定义这些参数,然后才能在工作流定义中的其他位置引用这些参数。
下面是参数定义的一般结构:
"parameters": {
"<parameter-name>": {
"type": "<parameter-type>",
"defaultValue": <default-parameter-value>,
"allowedValues": [ <array-with-permitted-parameter-values> ],
"metadata": {
"description": "<parameter-description>"
}
}
},
Attribute | Required | 类型 | Description |
---|---|---|---|
< parameter-name> | Yes | String | 要定义的参数的名称 |
< parameter-type> | Yes | int、float、string、bool、array、object、securestring、secureobject Note: For all passwords, keys, and secrets, use the securestring or secureobject types because the GET operation doesn't return these types. 若要详细了解如何保护参数,请参阅操作和输入参数的安全建议。 |
参数的类型 |
< default-parameter-value> | Yes | 与 type 相同 |
在工作流实例化时未指定值的情况下使用的默认参数值。
defaultValue 属性是逻辑应用设计器正确显示参数所必需的,但是你可以指定空值。 |
< array-with-permitted-parameter-values> | No | Array | 包含参数可接受的值的数组 |
< parameter-description> | No | JSON object | 任何其他的参数详细信息,例如参数的说明 |
接下来,请为工作流定义创建一个 Azure 资源管理器模板,定义模板参数来接收部署时需要的值,视情况将硬编码值替换为对模板或工作流定义参数的引用,并将需要在部署时使用的值存储在单独的参数文件中。 这样,无需更新和重新部署逻辑应用即可通过参数文件更轻松地更改这些值。 对于敏感的或者必须进行保护的信息(例如用户名、密码和机密),可将这些值存储在 Azure Key Vault 中,让参数文件从密钥保管库中检索这些值。 有关在模板和工作流定义级别定义参数的详细信息和示例,请参阅概述:使用 Azure 资源管理器模板自动部署逻辑应用。
Static results
在 staticResults
特性中,定义操作的模拟 outputs
和 status
,启用操作的静态结果设置时,操作将返回这些信息。 在操作的定义中,runtimeConfiguration.staticResult.name
特性引用 staticResults
中的静态结果定义的名称。 了解如何通过设置静态结果使用模拟数据测试逻辑应用工作流。
"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 | 类型 | Description |
---|---|---|---|
< static-result-definition-name> | Yes | String | 操作定义可通过 runtimeConfiguration.staticResult 对象引用的静态结果定义的名称。 有关详细信息,请参阅运行时配置设置。 可以使用所需的任意唯一名称。 默认情况下,此唯一名称的后面会追加一个按需递增的数字。 |
< output-attributes-and-values-returned> | Yes | Varies | 这些特性的要求因条件不同而异。 例如,如果 status 为 Succeeded ,则 outputs 特性包含操作作为模拟输出返回的特性和值。 如果 status 为 Failed ,则 outputs 特性包含 errors 特性,即提供错误信息的一个或多个错误 message 对象的数组。 |
< header-values> | No | JSON | 操作返回的任何标头值 |
< status-code-returned> | Yes | String | 操作返回的状态代码 |
< action-status> | Yes | String | 操作的状态,例如 Succeeded 或 Failed |
例如,在此 HTTP 操作定义中,runtimeConfiguration.staticResult.name
特性引用 HTTP0
中的定义了操作模拟输出的 staticResults
特性。
runtimeConfiguration.staticResult.staticResultOptions
特性指定 HTTP 操作的静态结果设置为 Enabled
。
"actions": {
"HTTP": {
"inputs": {
"method": "GET",
"uri": "https://www.microsoft.com"
},
"runAfter": {},
"runtimeConfiguration": {
"staticResult": {
"name": "HTTP0",
"staticResultOptions": "Enabled"
}
},
"type": "Http"
}
},
HTTP 操作在 HTTP0
内的 staticResults
定义中返回输出。 在此示例中,状态代码的模拟输出为 OK
。 标头值的模拟输出为 "Content-Type": "application/JSON"
。 操作状态的模拟输出为 Succeeded
。
"definition": {
"$schema": "<...>",
"actions": { "<...>" },
"contentVersion": "<...>",
"outputs": { "<...>" },
"parameters": { "<...>" },
"staticResults": {
"HTTP0": {
"outputs": {
"headers": {
"Content-Type": "application/JSON"
},
"statusCode": "OK"
},
"status": "Succeeded"
}
},
"triggers": { "<...>" }
},
Expressions
使用 JSON 可以获取设计时存在的文本值,例如:
"customerName": "Sophia Owen",
"rainbowColors": ["red", "orange", "yellow", "green", "blue", "indigo", "violet"],
"rainbowColorsCount": 7
还可以获取在运行时之前不存在的值。 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 字符串值中的任何位置使用表达式,并在表达式的前面加上 @ 符号前缀。 计算表示 JSON 值的表达式时,会通过删除 @ 字符来提取表达式主体,并且始终生成另一个 JSON 值。
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 ({}). 语法如下:
@{ "<expression1>", "<expression2>" }
结果始终是一个字符串。因此,此功能类似于 concat()
函数,例如:
"customerName": "First name: @{parameters('firstName')} Last name: @{parameters('lastName')}"
如果某个文本字符串以 @ 字符开头,请加上 @ 字符作为前缀,并加上另一个 @ 字符作为转义符:@@
这些示例演示如何计算表达式:
JSON value | Result |
---|---|
"Sophia Owen" | 返回这些字符:'Sophia Owen' |
"array[1]" | 返回这些字符:'array[1]' |
"@@" | 以单字符字符串的形式返回这些字符:\'\@\' |
" @" | 以双字符字符串的形式返回这些字符:\' \@\' |
这些示例假设定义了 "myBirthMonth" 等于 "January","myAge" 等于数字 42:
"myBirthMonth": "January",
"myAge": 42
这些示例演示如何计算以下表达式:
JSON expression | Result |
---|---|
"@parameters('myBirthMonth')" | 返回此字符串:"January" |
"@{parameters('myBirthMonth')}" | 返回此字符串:"January" |
"@parameters('myAge')" | 返回此数字:42 |
"@{parameters('myAge')}" | 以字符串形式返回此数字:"42" |
“我的年龄是 @{parameters('myAge')}” | 返回此字符串:"My age is 42" |
“@concat('我的年龄是',字符串(参数('myAge')))” | 返回此字符串:"My age is 42" |
“我的年龄是 @@{parameters('myAge')}” | 返回包含表达式的此字符串:"My age is @{parameters('myAge')}` |
在工作流设计器中以可视方式工作时,可以使用表达式编辑器创建表达式,例如:
完成后,将为工作流定义中的相应属性显示表达式,例如,下面的 searchQuery
属性:
"Search_tweets": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['x']['connectionId']"
}
}
},
"method": "get",
"path": "/searchtweets",
"queries": {
"maxResults": 20,
"searchQuery": "Azure @{concat('firstName','', 'LastName')}"
}
},
Outputs
在 outputs
节中,定义工作流在完成运行时可以返回的数据。 例如,若要跟踪每次运行的特定状态或值,请指定工作流输出应返回该数据。
Note
在响应来自服务 REST API 的传入请求时,请不要使用 outputs
。 请改用 Response
操作类型。
有关详细信息,请参阅工作流触发器和操作。
下面是输出定义的一般结构:
"outputs": {
"<key-name>": {
"type": "<key-type>",
"value": "<key-value>"
}
}
Attribute | Required | 类型 | Description |
---|---|---|---|
< key-name> | Yes | String | 输出返回值的密钥名称 |
< key-type> | Yes | int、float、string、securestring、bool、array、JSON 对象 | 输出返回值的类型 |
< key-value> | Yes | Same as <key-type> | 输出返回值 |
若要从工作流运行中获取输出,请在 Azure 门户中查看逻辑应用的运行历史记录和详细信息,或使用工作流 REST API。 也可将输出传递给 Power BI 等外部系统,以便可创建仪表板。
Operators
In expressions and functions, operators perform specific tasks, such as reference a property or a value in an array.
Operator | Task |
---|---|
' |
若要使用字符串文本作为输入,或者在表达式和函数中使用字符串文本,请仅使用单引号包装该字符串,例如 '<myString>' 。 请勿使用双引号 ("" ),这与整个表达式两侧的 JSON 格式相冲突。 For example: Yes: length('Hello') No: length("Hello") 如果传递数组或数字,则不需要包装标点符号。 For example: Yes: length([1, 2, 3]) No: length("[1, 2, 3]") |
[] |
要在数组或 JSON 对象内的特定位置(索引)引用值,请使用方括号,例如: - 获取数组中的第二项: myArray[1] - 访问 JSON 对象中的属性: Example 1: setProperty(<object>, '<parent-property>', addProperty(<object>['<parent-property>'], '<child-property>', <value>) Example 2: lastIndexOf(triggerBody()?['subject'],'some string') |
. |
若要引用对象中的属性,请使用点运算符。 例如,若要获取 name JSON 对象的 customer 属性:"parameters('customer').name" |
? |
To reference null properties in an object without a runtime error, use the null-ignore (?) operator. 例如,若要处理触发器中的 null 输出,可使用以下表达式:coalesce(trigger().outputs?.body?['<someProperty>'], '<property-default-value>') |
Functions
某些表达式从运行时操作获取其值,而这些操作在工作流定义开始运行时可能不存在。 To reference or work with these values in expressions, you can use functions that the Workflow Definition Language provides.