azure-devops - 如何在 Azure Pipeline 中为自定义条件处理 Null?

标签 azure-devops

我发现在自定义条件下查找变量的最佳方法是 null。

我试图比较 null。但是,如果我这样配置,Azure Pipeline 会提示导致错误。

and(failed(), ne(variables['Some'], Null))

此外,此配置不会引发错误,但是,当“Some”为空时,条件变为假。因为 Null 和 'Null' 是不同的。
and(failed(), ne(variables['Some'], 'Null'))

我最终想出了一个解决方法。然而,这不是很酷的方式。我添加了 PowerShell 任务,并创建了这个脚本。

if ($env:Some -eq $null) {
    Write-Host "##vso[task.setvariable variable=SkipSome]True"
}

然后配置自定义条件
and(failed(), ne(variables['SkipSome'], 'True'))

我希望有一种方法可以在没有 powershell 的情况下与 null 进行比较。但是,我在官方文档中找不到它。

最佳答案

How to deal with Null for custom condition in Azure Pipeline?



要处理自定义条件的 Null,我们应该使用 ''而不是 Null'Null' .

您可以查看 String一些细节。

所以,你可以像下面这样配置它:
and(failed(), ne(variables['Some'], ''))

为了更直观地测试它,我更改了 neeq :
and(failed(), eq(variables['Some'], ''))

然后我在变量选项卡上设置变量为空,并添加一个具有上述条件的内联 powershell 任务:

enter image description here

enter image description here

在日志中,我们可以看到任务被执行:

enter image description here

希望这可以帮助。

关于azure-devops - 如何在 Azure Pipeline 中为自定义条件处理 Null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56875665/

相关文章:

.net - Azure DevOps - 无法运行已安装的 dotnet 工具

node.js - Azure DevOps Pipeline 中的 Docker 镜像中的单元测试

git - 在 Powershell 中执行 git 命令

Azure VSTS : Nesting variables to get the value of a keyvault's secret

azure-devops - 有没有办法在 Visual Studio 团队服务中更改默认线程文化

ios - 如何在 xcode build 命令中传递预处理器宏名称?

visual-studio - 无法解析 Team Foundation Services 中的工作项

azure - 如何永久删除 Azure VSTS 项目内的文件夹?

azure-devops - 如何使用服务主体将角色分配给另一个服务主体

Azure 开发运营 : Service connection is not being recognized