为什么这些 Azure DevOps 预定义变量在管道构建中不起作用?

Pur*_*ome 1 azure-devops

鉴于以下 yml 代码段,此脚本中使用的 Azure DevOps Pipeline预定义变量不会被“拾取”。

pool:
  vmImage: 'Ubuntu 16.04'

variables:
  buildConfiguration: 'Release'

trigger:
  branches:
    include:
    - master
  paths:
    include:
  <snipped>
pr:
  autoCancel: false
  paths:
    include:
  <snipped>

steps:
# Remove this task once .NET Core 2.2 is added to hosted agent.
- task: DotNetCoreInstaller@0
  inputs:
    packageType: 'sdk'
    version: '2.2.100'

- script: dotnet build --configuration $(buildConfiguration) -p:Version=$(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r)
  displayName: 'dotnet build'
  workingDirectory: 'src/<snipped>'
Run Code Online (Sandbox Code Playgroud)

请注意我如何尝试设置 a 的 version 属性dotnet build

dotnet build --configuration $(buildConfiguration) -p:Version=$(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r)
Run Code Online (Sandbox Code Playgroud)

但!当我手动定义构建名称 .. 然后引用该变量 .. 它有效!

name: $(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r)

  <snipped>

- script: dotnet build --configuration $(buildConfiguration) -p:Version=$(Build.BuildNumber)
  displayName: 'dotnet build'
  workingDirectory: 'src/<snipped>'
Run Code Online (Sandbox Code Playgroud)

这是 Azure DevOps 的错误吗?

Sha*_*zyk 9

这些变量$(Year:yyyy) $(Month) $(DayOfMonth) $(Rev:r)不是常规预定义构建变量的一部分,如您所见,它们不存在于此处的列表中。

只能以内部版本号格式(name在 YAML 中)使用这些变量。

所以只是你做到了,你可以在那里使用它们,并在构建过程中使用变量Build.BuildNumber来获取值。