Devops YAML - 使用表达式设置构建名称

Mou*_*ess 1 variables yaml expression build-numbers azure-pipelines

在 yaml 构建中,是否可以使用表达式设置构建名称;如果我可以将发布管道与实际构建 ID 相匹配,那将是有利的。

例子:

trigger:  
- master

variables:  
    major: 2  
    minor: 3  
    offset: 2000  
    bid: $[$build.BuildID -as [int] + $offset]

name: "$(major).$(minor).$(bid)"

Run Code Online (Sandbox Code Playgroud)

dea*_*dog 9

您可以使用UpdateBuildNumber 命令将名称动态设置为 bash 或 PowerShell 脚本的一部分。

有关更多详细信息,您可以查看此博客文章,但其要点如下:

name: 'Set dynamically below in a task'

variables:  
    major: 2  
    minor: 3  
    offset: 2000

steps:
- task: PowerShell@2
  displayName: Set the name of the build (i.e. the Build.BuildNumber)
  inputs:
    targetType: 'inline'
    script: |
      [int] $buildIdWithOffset = ([int] $(Build.BuildId)) + ([int] $(offset))
      [string] $buildName = "$(major).$(minor).$buildIdWithOffset"
      Write-Host "Setting the name of the build to '$buildName'."
      Write-Host "##vso[build.updatebuildnumber]$buildName"
Run Code Online (Sandbox Code Playgroud)