摘要
返回环境变量的值。
语法
envvar(<variableName>)
说明
函数 envvar()
将环境变量的值作为字符串返回。 如果环境变量不存在,DSC 将引发错误。
示例
示例 1 - 配置中的引用DSC_CONFIG_ROOT
使用 --path
选项为任何 dsc config *
命令指定配置文档时,DSC 会自动创建 DSC_CONFIG_ROOT
环境变量,并将值设置为指定配置文档的父文件夹。 有关详细信息,请参阅 dsc config 命令参考。
此配置使用 资源回显该 Test/Echo
文件夹。
# ./examples/envvar.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Echo 'DSC_CONFIG_ROOT' in envvar
type: Test/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: Test/Echo
result:
actualState:
output: ~/dsc/examples
messages: []
hadErrors: false
参数
variableName
函数 envvar()
需要一个表示要使用的环境变量名称的字符串。 如果值不是字符串,则 DSC 在验证配置文档时会引发错误。 如果输入命名的环境变量不存在,DSC 将引发错误。
Type: string
Required: true
MinimumCount: 1
MaximumCount: 1
输出
函数 envvar()
返回使用 variableName 参数指定的环境变量的值。
Type: string