参数

概要

返回配置参数的值。

语法

parameters('<name>')

DESCRIPTION

parameters() 函数返回特定参数的值。 您必须传递有效参数的名称。 当对资源实例使用此函数时,DSC 会在此函数运行之后和为当前作调用资源之前验证实例属性。 如果引用的参数值对属性无效,DSC 将引发验证错误。

有关在配置文档中定义参数的更多信息,请参阅 DSC 配置文档的参数架构

例子

示例 1 - 使用参数作为资源实例属性值

该配置使用 function parameters() 来回显 parameter 的值 message

# parameters.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
  message:
    type:         string
    defaultValue: Hello, world!
resources:
  - name: Echo message parameter
    type: Microsoft.DSC.Debug/Echo
    properties:
      output: "[parameters('message')]"

首先,获取配置的当前状态,而不使用 --parameters--parameters_file options 覆盖参数。 输出显示参数的 message 默认值。

config_file=parameters.example.1.dsc.config.yaml
cat $config_file | dsc config get
results:
- name: Echo message parameter
  type: Microsoft.DSC.Debug/Echo
  result:
    actualState:
      output: Hello, world!
messages: []
hadErrors: false

接下来,使用 --parameters option 覆盖参数message

params='{"parameters": {"message": "Hi, override."}}'
cat $config_file | dsc config --parameters $params get
results:
- name: Echo message parameter
  type: Microsoft.DSC.Debug/Echo
  result:
    actualState:
      output: Hi, override.
messages: []
hadErrors: false

参数

姓名

parameters() 函数需要一个字符串作为输入,表示要返回的参数的名称。 如果配置文档中未定义具有指定名称的参数,DSC 会在验证过程中引发错误。

Type:         string
Required:     true
MinimumCount: 1
MaximumCount: 1

输出

parameters() 函数返回指定参数的值。

Type: [string, int, bool, object, array]