gpt4 book ai didi

azure - 如何在 Powershell 中访问 Azure DevOps 阶段名称?

转载 作者:行者123 更新时间:2023-12-03 03:41:11 26 4
gpt4 key购买 nike

我正在尝试编写一些 Powershell 逻辑,用于查看发布阶段名称并根据发布的环境实现一些代码。

例如,如果我的阶段名为“DEV”,我将执行 xyz,或者如果我的阶段名为“QA”,我将执行 abc...

我尝试过这样的事情:

 $s = $(Release.EnvironmentName)

$s = $(System.StageDisplayName)

if ($s -like "DEV")
{
// execute some code
}

但每次,它都会爆炸,因为它说“DEV”不是可识别的命令导出等。我尝试在 if block 中注入(inject)预定义变量,但它也会爆炸。

有语法方面的帮助吗?

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" {}
}

关于azure - 如何在 Powershell 中访问 Azure DevOps 阶段名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71117482/

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