azure-devops - lower() 函数在 Azure DevOps YAML 管道中似乎不起作用

标签 azure-devops azure-pipelines-yaml

我正在尝试在 YAML 模板中使用 lower() 函数,但不了解该行为。
我有一个名为 Infra.Environment.ShortName 的变量组,其值为“Dev”。
在我的 YAML 模板中,我从变量组中定义了一个变量:

  variables:
  - name: environmentShortName
    value: $(Infra.Environment.ShortName)
在一个任务中,我引用了这个变量:
- task: AzureResourceGroupDeployment@2
  displayName: 'Deploy Storage Account'
  inputs:
    azureSubscription: ${{ parameters.subscription }}
    resourceGroupName: mst-${{ lower(variables.environmentShortName) }}-infra
    location: '$(Infra.Environment.Region.Primary)'
    csmFile: '$(Pipeline.Workspace)/$(Build.DefinitionName)/Resources/infra-storageAccount.json'
    csmParametersFile: '$(Pipeline.Workspace)/$(Build.DefinitionName)/Resources/infra-storageAccount.parameters.json'
    deploymentOutputs: ArmOutputs
我尝试了不同的表达式,但不明白为什么我不能将变量组值转换为小写:
resourceGroupName: mst-${{ lower(variables.environmentShortName) }}-infra
=> mst-Dev-infra(较低的似乎不起作用)
resourceGroupName: ${{ format('mst-{0}-infra', lower(variables.environmentShortName)) }}
=> mst-Dev-infra(格式有效,但较低的无效)
resourceGroupName: $[format('mst-{0}-infra', lower(variables.environmentShortName))]
=> $[format('mst-{0}-infra',lower(variables.environmentShortName))](未评估表达式)
resourceGroupName: mst-${{ lower(variables['Infra.Environment.ShortName']) }}-infra
=> mst--infra(空值)
resourceGroupName: mst-${{ lower('Dev') }}-infra
=> mst-dev-infra(较低的作品具有恒定值)

最佳答案

解决方案是使用运行时变量,因为在编译时未解析变量组。运行时表达式有一些限制,但以下有效:

  - name: environmentShortName
    value: $[lower(variables['Infra.Environment.ShortName'])]

    resourceGroupName: mst-$(environmentShortName)-infra

关于azure-devops - lower() 函数在 Azure DevOps YAML 管道中似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63669006/

相关文章:

azure-devops - 如何使 yaml 管道依赖在前一个循环的上下文中工作?

asp.net-core - NET Core 3.1的Azure DevOps代码覆盖率

azure-devops - Azure Pipelines 将 YAML 用于具有不同变量值但没有 YAML 重复的多个环境(阶段)

Azure DevOps Pipeline Program 不包含适合入口点的静态 'Main' 方法

c# - MsBuild 在 Visual Studio Online 上找不到还原的 NuGet 包

angular - 使用 VS 2015 的 Angular 2 应用程序的 VSTS 中的“未知编译器选项库”

azure - 从变量中读取 Azure Key Vault 任务中的 secret 变量

Azure Pipelines,迭代文件

azure-devops - 如何将复杂的 DevOps 管道模板参数传递给脚本

azure-devops - 有条件地在 azure 管道中使用变量组