1

Given the following yml snippet, the Azure DevOps Pipeline predefined variables used in this script don't get 'picked up'.

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>'

Notice how i'm trying to set the version property of a dotnet build:

dotnet build --configuration $(buildConfiguration) -p:Version=$(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r)

BUT! when I manually define the build name .. and then reference that variable .. it works!

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

  <snipped>

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

is this a bug with Azure DevOps?

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

1 Answers1

9

The variables $(Year:yyyy) $(Month) $(DayOfMonth) $(Rev:r) are not part of the regular pre-defined build variables, as you can see, they do not exist in the list here.

You can use those variables only in the Build number format (name in the YAML).

So just you did, you can use them there and during the build use the variable Build.BuildNumber to get the value.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114