Azure YAML if-else 总是失败

发布于 2025-01-14 06:54:01 字数 763 浏览 4 评论 0原文

我最近正在使用 Azure 进行 CI/CD 设置。目标是让开发人员选择要创建的构建类型,即暂存/生产。

感谢 如何在 Azure DevOps Pipeline 中编写 if else 条件,我添加了以下代码 -

parameters:
- name: selectConfiguration
displayName: Select build configuration
type: string
default: Debug
values:
 - Debug
 - Release

variables:
- name: config
${{ if eq(variables['parameters.selectConfiguration'], 'Debug') }}:
  value: Debug
${{ else }}:
  value: Release

这给了我以下结果 -

在此处输入图像描述

但无论我在此单选组中选择什么,它总是运行 else 块。即 if-else 总是失败。对理解我在这里做错了什么有帮助吗?

I am recently doing an CI/CD setup using Azure. The goal is to have the developer select the type of build to be created i.e Staging / Prod.

Thanks to How to write if else condition in Azure DevOps Pipeline, I have added following code -

parameters:
- name: selectConfiguration
displayName: Select build configuration
type: string
default: Debug
values:
 - Debug
 - Release

variables:
- name: config
${{ if eq(variables['parameters.selectConfiguration'], 'Debug') }}:
  value: Debug
${{ else }}:
  value: Release

This gives me the following result -

enter image description here

But no matter what I select in this radio group, it always run the else block. i.e. the if-else always fails. Any help to understand what I am doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

櫻之舞 2025-01-21 06:54:01

尝试下面的方法,应该可以。我使用相同的逻辑在不同的代理池之间切换。

variables:
  ${{ if eq(parameters.selectConfiguration, 'Debug') }}: 
    config: Debug
  ${{ else }}:
    config: Release

Try the below, it should work. I am using the same logic to switch between different agent pools.

variables:
  ${{ if eq(parameters.selectConfiguration, 'Debug') }}: 
    config: Debug
  ${{ else }}:
    config: Release
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文