gpt4 book ai didi

azure-devops - 可以在 Azure Pipelines 中完成条件变量分配吗?

转载 作者:行者123 更新时间:2023-12-04 16:57:27 25 4
gpt4 key购买 nike

Azure Pipelines 有 ExpressionsConditions ,但我找不到将两个值之一分配给 variable 的方法,基于条件。

有什么办法可以完成这个伪代码的作用吗?

    ${{ if endsWith( variables['Build.SourceBranchName'], '/master' ) }}: 
buildVersion: variables['mavenVersion']
${{ else }}:
buildVersion: variables['Build.SourceBranchName']

最佳答案

这应该可以解决问题....

BuildVersion 被初始化为 $(Build.SourceBranch)
如果是主分支,则将其更改为 $(mavenVersion)
否则没有变化。

variables:
mavenVersion: '1.0'
buildVersion: $(Build.SourceBranch)

pool:
vmImage: 'ubuntu-latest'

steps:

- script: echo '##vso[task.setvariable variable=buildVersion]$(mavenVersion)'
displayName: "Set the buildVersion as mavenVersion if the Build.SourceBranch = 'refs/heads/master' "
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')

- script: echo $(buildVersion)
displayName: 'Printing the variable'

非主分支打印 'refs/heads/ branch_name ' 这是 mavenVersion
non-master branches prints 'refs/heads/branch_name' which is mavenVersion

master 分支打印 1.0,即 mavenVersion
master branch prints 1.0 which is mavenVersion

关于azure-devops - 可以在 Azure Pipelines 中完成条件变量分配吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57532138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com