首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure DevOps构建YML,不附加条件,不工作

Azure DevOps构建YML,不附加条件,不工作
EN

Stack Overflow用户
提问于 2021-03-11 17:55:17
回答 1查看 114关注 0票数 0

我试图根据build中的源分支以及设置发布版本变量来设置构建配置。

当我在不同的分支上测试时,isRelease被适当地设置为true或false,但是条件不起作用。不管isRelease是什么(真/假),构建配置总是'Debug‘。我试过多种语法。有什么帮助吗?

我有这个:

代码语言:javascript
复制
 trigger:
      branches:
       include:
         - develop,
         - release/*,
         - Release/*
    
    pool:
      name: 'MyPool'
    
    variables: 
      isRelease: $[contains(variables['Build.SourceBranch'], 'release')]
    
      ${{ if eq(variables['isRelease'], 'true') }}:
        buildConfiguration: 'Release'
        version.Major: '1',
        version.Minor: $[counter(variables['version.Major'], 1)]
        versionNumber: $(version.Major).$(version.Minor).$(Build.BuildNumber)'
    
      ${{ if eq(variables['isRelease'], 'false') }}:
        buildConfiguration: 'Debug'
    
    steps...
      echo: $(buildConfiguration) // is echoing literally $(buildConfiguration)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-11 18:04:31

尝试去掉附加变量并直接比较源分支,如下所示:

代码语言:javascript
复制
    variables: 
   
      ${{ if contains(variables['Build.SourceBranch'], 'release') }}:
        buildConfiguration: 'Release'
        version.Major: '1',
        version.Minor: $[counter(variables['version.Major'], 1)]
        versionNumber: $(version.Major).$(version.Minor).$(Build.BuildNumber)'
    
      ${{ if not(contains(variables['Build.SourceBranch'], 'release')) }}:
        buildConfiguration: 'Debug'

来自Microsoft上的模板表达式:

在编译时表达式(${{ }})中,您可以访问参数和静态定义的变量。

对我来说,这意味着具有运行时设置的变量将无法“输入”该模板表达式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66587926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档