【问题标题】:Is it possible to Update the Build Definition name using YAML in Azure Pipelines是否可以在 Azure Pipelines 中使用 YAML 更新构建定义名称
【发布时间】:2020-05-28 10:13:43
【问题描述】:

我正在尝试根据 YAML 运行时参数更新构建定义名称。我能够像下面这样实现这一点

name: ${{ parameters.source }} to ${{ parameters.target }} $(Date:yyyyMMdd).$(Rev:r)

但我想通过提供条件表达式来更新构建名称。 请让我知道这是否可以实现。

【问题讨论】:

    标签: azure-devops yaml azure-pipelines azure-yaml-pipelines


    【解决方案1】:

    你可以这样做

    ${{ if eq(variables['Build.SourceBranchName'], 'master') }}: stageName: prod

    点击this链接查看您可以使用的表达式的完整列表。

    【讨论】:

    • 这适用于构建定义名称吗?我知道如何在阶段和工作中使用条件表达式。但想使用条件表达式来更新构建定义名称。
    • stageName 是一个变量。因此,您可以使用条件来设置变量值并使用它来设置名称。试试看。
    • 我试过了,效果很好。非常感谢。但是,现在我无法在没有任何表达式的情况下附加另一个变量
    • 请分享代码。如果答案对你有用,你能接受它作为答案并投票吗?
    • variables: ${{ if and(eq(parameters.Target1, true), ne(parameters.Target2, true), eq(parameters.Target3, true)) }}: target: Target1 and Target3 - group: processVariables name: ${{ parameters.source }} to ${{ variables.target }} - $(Date:yyyyMMdd).$(Rev:r) 这里变量组定义出错,不知道如何处理
    【解决方案2】:

    您可以参考documentation,它描述了如何设置运行(内部版本)编号。

    如果定义您自己的变量 My.Variable,请将其引用为运行编号:

    $(Build.DefinitionName)_$(Build.DefinitionVersion)_$(Build.RequestedFor)_$(Build.BuildId)_$(My.Variable)
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2019-07-11
      • 1970-01-01
      • 2020-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 2018-05-27
      相关资源
      最近更新 更多