Azure Devops 参数条件

标签 azure azure-devops azure-pipelines

parameters:
- name: environment
  type: string
  default: dev

- name: region
  type: string
  default: ${{ if or(eq(parameters.environment, 'dev'), eq(parameters.environment, 'tst')) }}central${{ else }}${{ if eq(parameters.environment, 'both') }}central, east${{ else }}east${{ endif }}${{ endif }}

我将条件设置为如果参数环境是开发或测试,那么参数区域将是中央,对于其他环境,该区域将是中央、东部、两者

但同时我收到错误,因为嵌入的表达式不支持指令

最佳答案

我不相信您可以在参数中运行表达式。为了实现所需的行为,我认为您宁愿运行表达式来根据条件设置变量值。

所以会是:

parameters:
- name: environment
  type: string
  default: dev

variables:
  ${{ if or(eq(parameters.environment, 'dev'), eq(parameters.environment, 'tst')) }}:
    region: 'central'
  ${{ if eq(parameters.environment, 'both') }} :
    region: 'central, east'
  ${{ else }} :
    region: 'east'

我还没有测试过这个;然而,这种方法应该有效。然后,您可以将您的区域引用为 ${{ Variables.region}} ,并可以将其传递给 future 的输入/模板。

这是一个stackoverflow post这也提供了一个例子。

关于Azure Devops 参数条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76575287/

相关文章:

azure-devops - 更新 Azure DevOps 中不同存储库中的 NuGet 引用

node.js - 如何在 Team Foundation Server 专用 Macos 代理上设置环境变量?

c# - Azure Application Insights - 自定义警报

c# - 在 Azure Function 中运行 .exe 可执行文件

android - Azure Pipeline - 自动化 Android 版本代码

git - Azure DevOps Pipeline 不会根据另一个分支触发

azure - 从 Datafactory IDE 删除管道

azure - 如何在发布构建期间用 configSource 替换连接字符串文件?

c# - 如何将字符串从 native 代码返回到 Windows Azure 中的托管代码?

azure - 使用个人访问 token 部署 Azure Function