envvar

概要

返回环境变量的值。

语法

envvar(<variableName>)

DESCRIPTION

envvar() 函数以字符串形式返回环境变量的值。 如果环境变量不存在,DSC 将引发错误。

例子

示例 1 - 配置中的引用 DSC_CONFIG_ROOT

当您使用选项 --path 为任何 dsc config * 命令指定配置文档时,DSC 会自动创建 DSC_CONFIG_ROOT 环境变量并将值设置为指定配置文档的父文件夹。 有关更多信息,请参阅 dsc config 命令参考

此配置将该文件夹与 Microsoft.DSC.Debug/Echo 资源相呼应。

# ./examples/envvar.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
  - name: Echo 'DSC_CONFIG_ROOT' in envvar
    type: Microsoft.DSC.Debug/Echo
    properties:
      output: "[envvar('DSC_CONFIG_ROOT')]"
dsc config get --path ~/dsc/examples/envvar.example.1.dsc.config.yaml
results:
- name: Echo DSC_CONFIG_ROOT
  type: Microsoft.DSC.Debug/Echo
  result:
    actualState:
      output: ~/dsc/examples
messages: []
hadErrors: false

参数

变量名称

envvar() 函数需要一个字符串,该字符串表示要使用的环境变量的名称。 如果值不是字符串,则 DSC 在验证配置文档时会引发错误。 如果输入命名的环境变量不存在,DSC 会引发错误。

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

输出

envvar() 函数返回使用 variableName 参数指定的环境变量的值。

Type: string