如何使用YAML条件插入添加乘法变量
我读了这份文件 但与文档中演示的不同,我需要添加三个条件相同的变量,如下所示:如何使用YAML条件插入添加乘法变量,yaml,azure-pipelines,Yaml,Azure Pipelines,我读了这份文件 但与文档中演示的不同,我需要添加三个条件相同的变量,如下所示: name: arm_temp resources: repositories: - repository: self type: git variables: - ${{ if in(lower(coalesce(variables['ENV'], variables['Build.SourceBranchName'])), 'release', 'prod') }}: - newE
name: arm_temp
resources:
repositories:
- repository: self
type: git
variables:
- ${{ if in(lower(coalesce(variables['ENV'], variables['Build.SourceBranchName'])), 'release', 'prod') }}:
- newEnv: 'Prod'
- account: '$(ACCOUNT)'
- password: '$(PASSWORD)'
- ${{ if eq(lower(coalesce(variables['ENV'], variables['Build.SourceBranchName'])), 'qa') }}:
- newEnv: 'QA'
- account: '$(ACCOUNT)'
- password: '$(PASSWORD)'
- resGroupName: ${{ format('RESGROUP-{0}', variables['newEnv']) }}
帐户、密码和环境是azure构建管道中定义的变量
但我总是在运行构建管道之前出错
错误通知是关于if条件下的行的。从Yaml示例来看,Yaml格式似乎有一些问题 您可以参考以下YAML示例:
variables:
${{ if in(lower(coalesce(variables['ENV'], variables['Build.SourceBranchName'])), 'release', 'prod') }}:
newEnv: 'Prod'
account: $(myaccount)
password: $(mypassword)
${{ if eq(lower(coalesce(variables['ENV'], variables['Build.SourceBranchName'])), 'qa') }}:
newEnv: 'QA'
account: $(myaccount)
password: $(mypassword)
resGroupName: ${{ format('RESGROUP-{0}', variables['newEnv']) }}
pool:
vmimage: windows-latest
steps:
- script: |
echo $(newEnv)
echo $(account)
echo $(password)
变量:
结果:
注意:您需要更改变量名
$(帐户)
$(密码)
。它们不能与yaml中定义的变量同名($(帐户),$(密码)
)。或者变量无法成功传递。谢谢,我尝试过使用它,但输出为:$(newEnv)$(account)$(password)Hi@frank。您需要确保满足if表达式的条件。然后将设置变量。或者它不会设置正确的变量。我建议你可以简化if表达式来测试。为了指出这一点,我的条件似乎有问题。