如何在 Powershell 中访问 Azure DevOps 阶段名称?
How to access Azure DevOps Stage name in Powershell?
我正在尝试编写一些 Powershell 逻辑来查看发布阶段名称并根据发布到的环境实现一些代码。
例如,如果我的阶段名为“DEV”,我将执行 xyz,或者如果我的阶段为“QA”,我将执行 abc...
我试过这样的事情:
$s = $(Release.EnvironmentName)
$s = $(System.StageDisplayName)
if ($s -like "DEV")
{
// execute some code
}
但每次它都会爆炸,因为它说“DEV”不是可识别的命令出口等。我尝试在 if 块中注入预定义变量,但它也爆炸了。
有语法方面的帮助吗?
DEV : The term 'DEV' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
2022-02-14T19:50:59.5173313Z spelling of the name, or if a path was included, verify that the path is correct and try again.
2022-02-14T19:50:59.5174118Z At D:\_agent1\_work\_temp\....ps1:37 char:21
2022-02-14T19:50:59.5174759Z + if (DEV -like DEV)
2022-02-14T19:50:59.5175946Z + ~~~
2022-02-14T19:50:59.5176689Z + CategoryInfo : ObjectNotFound: (DEV:String) [], ParentContainsErrorRecordException
2022-02-14T19:50:59.5177416Z + FullyQualifiedErrorId : CommandNotFoundException
如果 azure devops 变量没有引号,我的 Powershell 脚本将无法运行,请尝试这样的操作:
$branchSource = "$(Build.SourceBranch)"
$branchSourcePath = $branchSource -replace "refs/heads/", ""
switch -Wildcard ( $branchSourcePath )
{
"rc" {}
"develop" {}
}
我正在尝试编写一些 Powershell 逻辑来查看发布阶段名称并根据发布到的环境实现一些代码。
例如,如果我的阶段名为“DEV”,我将执行 xyz,或者如果我的阶段为“QA”,我将执行 abc...
我试过这样的事情:
$s = $(Release.EnvironmentName)
$s = $(System.StageDisplayName)
if ($s -like "DEV")
{
// execute some code
}
但每次它都会爆炸,因为它说“DEV”不是可识别的命令出口等。我尝试在 if 块中注入预定义变量,但它也爆炸了。
有语法方面的帮助吗?
DEV : The term 'DEV' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
2022-02-14T19:50:59.5173313Z spelling of the name, or if a path was included, verify that the path is correct and try again.
2022-02-14T19:50:59.5174118Z At D:\_agent1\_work\_temp\....ps1:37 char:21
2022-02-14T19:50:59.5174759Z + if (DEV -like DEV)
2022-02-14T19:50:59.5175946Z + ~~~
2022-02-14T19:50:59.5176689Z + CategoryInfo : ObjectNotFound: (DEV:String) [], ParentContainsErrorRecordException
2022-02-14T19:50:59.5177416Z + FullyQualifiedErrorId : CommandNotFoundException
如果 azure devops 变量没有引号,我的 Powershell 脚本将无法运行,请尝试这样的操作:
$branchSource = "$(Build.SourceBranch)"
$branchSourcePath = $branchSource -replace "refs/heads/", ""
switch -Wildcard ( $branchSourcePath )
{
"rc" {}
"develop" {}
}