gpt4 book ai didi

powershell - Azure DevOps 的 PowerShell 任务中是否提供管道变量?

转载 作者:行者123 更新时间:2023-12-04 12:05:44 25 4
gpt4 key购买 nike

我有这个 PowerShell 脚本,它读取一些环境变量并输出它们:

Write-Host "name: $(tenantName) version: $(versionRelease) url: $(urlApplication)"

这些变量定义为管道变量,也定义为 Azure DevOps 发布管道中的变量组。

当在 PowerShell task 内运行时定义为 内联 ,此脚本按预期工作。但是,当 PowerShell 任务配置为 时,完全相同的脚本将不起作用。文件路径 .在这种情况下, tenantName找不到 env 变量:
tenantName : The term 'tenantName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

有什么方法可以使环境变量可用于"file"脚本,就像它们可用于“内联”脚本一样?

最佳答案

我设法修复了它,部分归功于@Cbsch 的回答。确实,我的 PowerShell 脚本的语法不正确,但正在更改 $(tenantName)$tenantName没有解决问题,因为 $tenantName不存在。我不得不从环境变量中读取它,使用 $env:<variableName>句法。

固定脚本:

Write-Host "name: $env:tenantName version: $env:versionRelease url: $env:urlApplication"

关于powershell - Azure DevOps 的 PowerShell 任务中是否提供管道变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62409132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com